Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
durswd committed Jul 23, 2023
1 parent 60031b0 commit 6ea515a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Dev/Cpp/Effekseer/Effekseer/Utils/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ class FixedSizeString
return data_[i];
}

T back() const
{
return data_[size_ - 1];
}

const T* data() const
{
return data_.data();
Expand All @@ -151,6 +156,18 @@ class FixedSizeString
return size_;
}

FixedSizeString<T, N>& operator+=(const T& c)
{
if (size_ < data_.size() - 2)
{
data_[size_] = c;
data_[size_ + 1] = 0;
size_ += 1;
}

return *this;
}

bool operator==(const FixedSizeString<T, N>& rhs) const
{
return size() == rhs.size() && Traits::compare(data(), rhs.data(), size()) == 0;
Expand Down Expand Up @@ -462,7 +479,7 @@ class PathHelper
std::basic_string<T> ret = path1;
if (!IsSeparator(ret.back()))
{
ret += StringHelper::To<T>("/");
ret += static_cast<T>('/');
}
ret += path2;

Expand Down
13 changes: 13 additions & 0 deletions Dev/Cpp/Test/Runtime/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ void FixedSizeStringTest()
TEST_EQUAL_STR((std::u16string(u"12345").substr(0, 2)), (Effekseer::FixedSizeString<char16_t, 5>(u"12345").substr(0, 2).data()));
TEST_EQUAL_STR((std::u16string(u"12345").substr(1)), (Effekseer::FixedSizeString<char16_t, 5>(u"12345").substr(1).data()));
TEST_EQUAL_STR((std::u16string(u"12345").substr(1, 2)), (Effekseer::FixedSizeString<char16_t, 5>(u"12345").substr(1, 2).data()));

TEST_EQUAL_STR((std::u16string(u"1234").back()), (Effekseer::FixedSizeString<char16_t, 4>(u"1234").back()));

{
auto v1 = std::u16string(u"1234");
auto v2 = Effekseer::FixedSizeString<char16_t, 8>(u"1234");
v1 += '5';
v2 += '5';
TEST_EQUAL_STR(v1, v2.data());
}
}

void StringAndPathHelperTest()
Expand Down Expand Up @@ -87,6 +97,9 @@ void StringAndPathHelperTest()
TEST_EQUAL_STR((std::u16string(u"/b/a")), (Effekseer::PathHelper::Combine(std::u16string(u"/b"), std::u16string(u"a"))));

TEST_EQUAL_STR((std::u16string(u"/b/a/")), (Effekseer::PathHelper::Combine(std::u16string(u"/b/"), std::u16string(u"a/"))));

std::string str;
str += 'a';
}

#if defined(__linux__) || defined(__APPLE__) || defined(WIN32)
Expand Down

0 comments on commit 6ea515a

Please sign in to comment.