• R/O
  • SSH
  • HTTPS

qrobosdk: コミット


コミットメタ情報

リビジョン1789 (tree)
日時2010-04-18 09:23:16
作者satofumi

ログメッセージ

fixed Utf8::c_str() bug

変更サマリ

差分

--- trunk/libs/input/TestUtf8.cpp (revision 1788)
+++ trunk/libs/input/TestUtf8.cpp (revision 1789)
@@ -96,6 +96,14 @@
9696
9797 actual.pop_back();
9898 CPPUNIT_ASSERT_EQUAL(string(""), string(actual.c_str()));
99+
100+
101+ actual = Utf8("わっg");
102+ actual.pop_back();
103+ CPPUNIT_ASSERT_EQUAL(string("わっ"), string(actual.c_str()));
104+
105+ actual = Utf8(actual.c_str());
106+ CPPUNIT_ASSERT_EQUAL(string("わっ"), string(actual.c_str()));
99107 }
100108
101109
--- trunk/libs/input/Utf8.cpp (revision 1788)
+++ trunk/libs/input/Utf8.cpp (revision 1789)
@@ -38,6 +38,7 @@
3838 {
3939 string utf8_text_;
4040 vector<size_t> index_;
41+ string c_string_;
4142
4243
4344 pImpl(const string& utf8_text) : utf8_text_(utf8_text)
@@ -121,7 +122,7 @@
121122
122123 const char* Utf8::c_str(void)
123124 {
124- string c_string;
125+ pimpl->c_string_.clear();
125126
126127 size_t n = pimpl->index_.size();
127128 for (size_t i = 0; i < n; ++i) {
@@ -128,14 +129,14 @@
128129 size_t index = pimpl->utf8_index(i);
129130 const unsigned short ch = pimpl->utf8_text_[index];
130131 if (ch & 0xff00) {
131- c_string.push_back(ch);
132- c_string.push_back(pimpl->utf8_text_[index + 1]);
133- c_string.push_back(pimpl->utf8_text_[index + 2]);
132+ pimpl->c_string_.push_back(ch);
133+ pimpl->c_string_.push_back(pimpl->utf8_text_[index + 1]);
134+ pimpl->c_string_.push_back(pimpl->utf8_text_[index + 2]);
134135 } else {
135- c_string.push_back(ch);
136+ pimpl->c_string_.push_back(ch);
136137 }
137138 }
138- return c_string.c_str();
139+ return pimpl->c_string_.c_str();
139140 }
140141
141142
--- trunk/libs/input/Makefile (revision 1788)
+++ trunk/libs/input/Makefile (revision 1789)
@@ -52,5 +52,5 @@
5252 TestConvertToRoman.o: TestConvertToRoman.h convertToRoman.h roman_table.h
5353 TestUtf8.o: TestUtf8.h Utf8.h
5454 Utf8.o: Utf8.h
55-convertToJp.o: convertToJp.h roman_table.h kana_table.h
55+convertToJp.o: convertToJp.h roman_table.h kana_table.h Utf8.h
5656 convertToRoman.o: convertToRoman.h roman_table.h Utf8.h
旧リポジトリブラウザで表示