• R/O
  • SSH
  • HTTPS

qrobosdk: コミット


コミットメタ情報

リビジョン1788 (tree)
日時2010-04-18 08:02:11
作者satofumi

ログメッセージ

add Utf8::pop_back()

変更サマリ

差分

--- trunk/libs/input/TestUtf8.cpp (revision 1787)
+++ trunk/libs/input/TestUtf8.cpp (revision 1788)
@@ -67,3 +67,57 @@
6767 CPPUNIT_ASSERT_EQUAL(Utf8("い")[0], mix_text[4]);
6868 CPPUNIT_ASSERT_EQUAL(Utf8("う")[0], mix_text[5]);
6969 }
70+
71+
72+void TestUtf8::c_strTest(void)
73+{
74+ Utf8 actual = Utf8("a");
75+ CPPUNIT_ASSERT_EQUAL(string("a"), string(actual.c_str()));
76+
77+ actual = Utf8("あ");
78+ CPPUNIT_ASSERT_EQUAL(string("あ"), string(actual.c_str()));
79+
80+ actual = Utf8("あい");
81+ CPPUNIT_ASSERT_EQUAL(string("あい"), string(actual.c_str()));
82+
83+ actual = Utf8("");
84+ CPPUNIT_ASSERT_EQUAL(string(""), string(actual.c_str()));
85+}
86+
87+
88+void TestUtf8::pop_backTest(void)
89+{
90+ Utf8 actual = Utf8("あい");
91+ actual.pop_back();
92+ CPPUNIT_ASSERT_EQUAL(string("あ"), string(actual.c_str()));
93+
94+ actual.pop_back();
95+ CPPUNIT_ASSERT_EQUAL(string(""), string(actual.c_str()));
96+
97+ actual.pop_back();
98+ CPPUNIT_ASSERT_EQUAL(string(""), string(actual.c_str()));
99+}
100+
101+
102+#if 0
103+void TestUtf8::substrTest(void)
104+{
105+ Utf8 actual = Utf8("あいう");
106+ CPPUNIT_ASSERT_EQUAL(string("あい"), string(actual.substr(0, 2).c_str()));
107+
108+ actual = Utf8("あいう");
109+ CPPUNIT_ASSERT_EQUAL(string("あ"), string(actual.substr(0, 1).c_str()));
110+
111+ actual = Utf8("あいう");
112+ CPPUNIT_ASSERT_EQUAL(string("いう"), string(actual.substr(1, 2).c_str()));
113+
114+ actual = Utf8("あいう");
115+ CPPUNIT_ASSERT_EQUAL(string("う"), string(actual.substr(2, 3).c_str()));
116+
117+ actual = Utf8("う");
118+ CPPUNIT_ASSERT_EQUAL(string("あいう"), string(actual.substr(0, -1).c_str()));
119+
120+ actual = Utf8("あいう");
121+ CPPUNIT_ASSERT_EQUAL(string("あい"), string(actual.substr(0, -2).c_str()));
122+}
123+#endif
--- trunk/libs/input/Utf8.cpp (revision 1787)
+++ trunk/libs/input/Utf8.cpp (revision 1788)
@@ -117,3 +117,44 @@
117117 }
118118 return ch;
119119 }
120+
121+
122+const char* Utf8::c_str(void)
123+{
124+ string c_string;
125+
126+ size_t n = pimpl->index_.size();
127+ for (size_t i = 0; i < n; ++i) {
128+ size_t index = pimpl->utf8_index(i);
129+ const unsigned short ch = pimpl->utf8_text_[index];
130+ 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]);
134+ } else {
135+ c_string.push_back(ch);
136+ }
137+ }
138+ return c_string.c_str();
139+}
140+
141+
142+void Utf8::pop_back(void)
143+{
144+ if (! pimpl->index_.empty()) {
145+ pimpl->index_.pop_back();
146+ }
147+}
148+
149+
150+#if 0
151+Utf8& Utf8::substr(size_t first, size_t last)
152+{
153+ (void)first;
154+ (void)last;
155+
156+ // !!!
157+
158+ return *this;
159+}
160+#endif
--- trunk/libs/input/Utf8.h (revision 1787)
+++ trunk/libs/input/Utf8.h (revision 1788)
@@ -34,6 +34,12 @@
3434 void clear(void);
3535 size_t size(void);
3636 unsigned short operator[](size_t index);
37+
38+ const char* c_str(void);
39+
40+ void pop_back(void);
41+
42+ //Utf8& substr(size_t first, size_t last = std::string::npos);
3743 };
3844 }
3945
--- trunk/libs/input/TestUtf8.h (revision 1787)
+++ trunk/libs/input/TestUtf8.h (revision 1788)
@@ -3,7 +3,7 @@
33
44 /*!
55 \file
6- \brief Utf8 のテスト
6+ \brief Utf8.cpp のテスト
77
88 \author Satofumi KAMIMURA
99
@@ -21,6 +21,9 @@
2121 CPPUNIT_TEST(emptyTest);
2222 CPPUNIT_TEST(sizeTest);
2323 CPPUNIT_TEST(chTest);
24+ CPPUNIT_TEST(c_strTest);
25+ CPPUNIT_TEST(pop_backTest);
26+ //CPPUNIT_TEST(substrTest);
2427 CPPUNIT_TEST_SUITE_END();
2528
2629 public:
@@ -27,6 +30,9 @@
2730 void emptyTest(void);
2831 void sizeTest(void);
2932 void chTest(void);
33+ void c_strTest(void);
34+ void pop_backTest(void);
35+ //void substrTest(void);
3036 };
3137
3238 #endif /* !TEST_UTF8_H */
旧リポジトリブラウザで表示