Skip to content

Commit

Permalink
Merge c0bee56 into ee7b9af
Browse files Browse the repository at this point in the history
  • Loading branch information
berryzplus authored Nov 23, 2019
2 parents ee7b9af + c0bee56 commit 3a54f03
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
17 changes: 13 additions & 4 deletions sakura_core/mem/CNativeW.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,19 @@ class CNativeW final : public CNative{
//演算子
CNativeW& operator = (const CNativeW& rhs) { CNative::operator=(rhs); return *this; }
CNativeW& operator = (CNativeW&& rhs) noexcept { CNative::operator=(std::forward<CNativeW>(rhs)); return *this; }
const CNativeW& operator+=(wchar_t wch) { AppendString(&wch,1); return *this; }
const CNativeW& operator=(wchar_t wch) { SetString(&wch,1); return *this; }
const CNativeW& operator+=(const CNativeW& rhs) { AppendNativeData(rhs); return *this; }
CNativeW operator+(const CNativeW& rhs) const { CNativeW tmp=*this; return tmp+=rhs; }
CNativeW operator + (const CNativeW& rhs) const { return std::move(CNativeW(*this) += rhs); }
CNativeW& operator += (const CNativeW& rhs) { AppendNativeData(rhs); return *this; }

CNativeW& operator = (wchar_t ch)
{
if (!ch) return (*this = nullptr);
return (*this = CNativeW(&ch, 1));
}
CNativeW& operator += (wchar_t ch)
{
const wchar_t sz[]{ ch, 0 };
return (*this += sz);
}

//ネイティブ取得インターフェース
wchar_t operator[](int nIndex) const; //!< 任意位置の文字取得。nIndexは文字単位。
Expand Down
24 changes: 8 additions & 16 deletions tests/unittests/test-cnative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,23 +253,19 @@ TEST(CNativeW, AssignStringNullPointer)

/*!
* @brief 代入演算子(NULL指定)の仕様
* @remark バッファが確保される
* @remark 文字列長は1になる
* @remark バッファサイズは1+1以上になる
* @note バグですね(^^;
* @remark バッファを確保している場合は解放される
* @remark 文字列長はゼロになる
*/
TEST(CNativeW, AssignStringNullLiteral)
{
CNativeW value;
CNativeW value(L"test");
#ifdef _MSC_VER
value = NULL; // operator = (wchar_t) と解釈される
#else
value = static_cast<wchar_t>(NULL);
#endif
ASSERT_STREQ(L"", value.GetStringPtr());
EXPECT_EQ(1, value.GetStringLength());
EXPECT_LT(1 + 1, value.capacity());
EXPECT_EQ(0, value[0]); // 長さ=1なので1文字目を参照できるが、NULが返ってくる
ASSERT_EQ(NULL, value.GetStringPtr());
EXPECT_EQ(0, value.GetStringLength());
}

/*!
Expand Down Expand Up @@ -321,10 +317,7 @@ TEST(CNativeW, AppendStringNullPointer)

/*!
* @brief 加算代入演算子(NULL指定)の仕様
* @remark バッファが確保される
* @remark 文字列長は1になる
* @remark バッファサイズは1+1以上になる
* @note バグですね(^^;
* @remark 加算代入しても内容に変化無し
*/
TEST(CNativeW, AppendStringNullLiteral)
{
Expand All @@ -334,9 +327,8 @@ TEST(CNativeW, AppendStringNullLiteral)
#else
value += static_cast<wchar_t>(NULL);
#endif
ASSERT_STREQ(L"", value.GetStringPtr());
EXPECT_EQ(1, value.GetStringLength());
EXPECT_LT(1 + 1, value.capacity());
ASSERT_EQ(NULL, value.GetStringPtr());
EXPECT_EQ(0, value.GetStringLength());
}

/*!
Expand Down

0 comments on commit 3a54f03

Please sign in to comment.