• R/O
  • SSH
  • HTTPS

qrobosdk: コミット


コミットメタ情報

リビジョン1786 (tree)
日時2010-04-18 00:52:55
作者satofumi

ログメッセージ

テスト通過

変更サマリ

差分

--- trunk/libs/input/TestConvertToJp.cpp (revision 1785)
+++ trunk/libs/input/TestConvertToJp.cpp (revision 1786)
@@ -51,9 +51,14 @@
5151 CPPUNIT_ASSERT_EQUAL(Utf8("c")[0], actual[0]);
5252 CPPUNIT_ASSERT_EQUAL(Utf8("ば")[0], actual[1]);
5353
54+ actual = Utf8(convertToJp("kk"));
55+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), actual.size());
56+ CPPUNIT_ASSERT_EQUAL(Utf8("っ")[0], actual[0]);
57+ CPPUNIT_ASSERT_EQUAL(Utf8("k")[0], actual[1]);
58+
5459 actual = Utf8(convertToJp("kka"));
5560 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), actual.size());
56- CPPUNIT_ASSERT_EQUAL(Utf8("c")[0], actual[0]);
61+ CPPUNIT_ASSERT_EQUAL(Utf8("っ")[0], actual[0]);
5762 CPPUNIT_ASSERT_EQUAL(Utf8("か")[0], actual[1]);
5863
5964 actual = Utf8(convertToJp("shi"));
--- trunk/libs/input/convertToJp.cpp (revision 1785)
+++ trunk/libs/input/convertToJp.cpp (revision 1786)
@@ -49,14 +49,15 @@
4949 // 先頭文字から比較と変換を行う
5050 for (size_t match_start = 0; match_start < converted.size(); ++match_start) {
5151 for (const unsigned short* pattern = table;
52- *pattern != 0x0; pattern += pattern_max_size) {
52+ *pattern != 0x0; pattern += (pattern_max_size * 2)) {
53+ size_t current_size = converted.size();
5354
5455 bool matched = true;
5556 int match_index = 0;
56- for (; *(pattern + match_index) != 0x0; ++match_index) {
57-
58- unsigned short ch = *(table + match_index);
59- if (ch != converted[match_start + match_index]) {
57+ unsigned short ch;
58+ for (; (ch = *(pattern + match_index)) != 0x0; ++match_index) {
59+ size_t ch_index = match_start + match_index;
60+ if ((current_size <= ch_index) || (ch != converted[ch_index])) {
6061 matched = false;
6162 break;
6263 }
@@ -68,15 +69,17 @@
6869 size_t matched_size = match_index;
6970 size_t replaced_size = short_strlen(pattern + pattern_max_size);
7071
71- vector<unsigned short>::iterator it = converted.begin() + match_start;
72- for (size_t i = 0; i < (matched_size - replaced_size); ++i) {
73- it = converted.erase(it);
74- }
75-
7672 // 置換する
7773 for (size_t i = 0; i < replaced_size; ++i) {
7874 converted[match_start + i] = *(pattern + pattern_max_size + i);
7975 }
76+
77+ vector<unsigned short>::iterator it =
78+ converted.begin() + match_start + matched_size - 1;
79+ for (size_t i = 0; i < (matched_size - replaced_size); ++i) {
80+ it = converted.erase(it);
81+ --it;
82+ }
8083 break;
8184 }
8285 }
--- trunk/libs/input/convertToRoman.cpp (revision 1785)
+++ trunk/libs/input/convertToRoman.cpp (revision 1786)
@@ -43,12 +43,14 @@
4343 match_start >= 0; --match_start) {
4444 for (int pattern_index = 0;
4545 RomanTable[pattern_index][1][0] != 0x0; ++pattern_index) {
46+ int current_size = converted.size();
4647
4748 bool matched = true;
4849 int match_index = 0;
4950 for (; RomanTable[pattern_index][1][match_index] != 0x0; ++match_index) {
5051 unsigned short ch = RomanTable[pattern_index][1][match_index];
51- if (ch != converted[match_start + match_index]) {
52+ int ch_index = match_start + match_index;
53+ if ((current_size <= ch_index) || (ch != converted[ch_index])) {
5254 matched = false;
5355 break;
5456 }
--- trunk/libs/input/Makefile (revision 1785)
+++ trunk/libs/input/Makefile (revision 1786)
@@ -48,7 +48,7 @@
4848 # DO NOT DELETE
4949
5050 convertToRoman.o: roman_table.h
51-TestConvertToJp.o: TestConvertToJp.h convertToJp.h
51+TestConvertToJp.o: TestConvertToJp.h convertToJp.h Utf8.h
5252 TestConvertToRoman.o: TestConvertToRoman.h convertToRoman.h roman_table.h
5353 TestUtf8.o: TestUtf8.h Utf8.h
5454 Utf8.o: Utf8.h
旧リポジトリブラウザで表示