CHNLIB_UIPArray *AI_Think_SlideLookUpWordByHistory(CHNLIB_String *input)\r
{\r
//入力文字列と履歴文字列を照らし合わせ、単語の候補を抜き出す。\r
+ //候補単語は、新たに確保されたUIPArrayに格納され、そのArrayへのポインタを返す。\r
+ //data32=入力文字列中に含まれる候補単語の数。\r
+ //pointer=候補単語を示すCHNLIB_String.\r
+ //[UTF-8]\r
CHNLIB_UIPArray *candidatewordlist;\r
int i, i_max;\r
int j, j_max;\r
int k, k_max;\r
+ const char *cstr_input, *cstrp_input;\r
+ const char *cstr_history, *cstrp_history;\r
int candidatelength, templength;\r
- const char *cstr_input, *cstr_history;\r
+ int cstrp_input_length;\r
\r
candidatewordlist = CHNLIB_UIPArray_Initialize();\r
- \r
i_max = CHNLIB_UIPArray_GetNumberOfDatas(WorkingSet.InputHistory);\r
\r
cstr_input = CHNLIB_String_GetReferencePointerOfCString(input);\r
- k_max = CHNLIB_CString_GetLength(cstr_input);\r
-\r
+ k_max = CHNLIB_UTF8_GetStringLengthByCharacter(cstr_input);\r
+ cstrp_input = cstr_input;\r
+ \r
for(k = 0; k < k_max; k++){\r
- //**UTF-8 only\r
- //UTF-8のマルチバイト部分でないことを確認\r
- if(CHNLIB_UTF8_GetCharacterType(cstr_input[k]) != 0){\r
- //****\r
- candidatelength = 0;\r
- for(i = 0; i < i_max; i++){\r
- cstr_history = CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(WorkingSet.InputHistory, i));\r
- j_max = CHNLIB_CString_GetLength(cstr_history);\r
- for(j = 0; j < j_max; j++){\r
- templength = CHNLIB_CString_CompareString_LeftHand(&cstr_history[j], &cstr_input[k]);\r
- if(templength > candidatelength && templength != (k_max - k)){\r
- //前方一致の長さが、\r
- //これまで見つかった単語よりも長く、かつ\r
- //入力文字列の検索部分の全長ではない場合、\r
- //単語の候補とする。\r
- candidatelength = templength;\r
- }\r
+ //input character loop\r
+ candidatelength = 0;\r
+ cstrp_input_length = CHNLIB_UTF8_GetStringLengthByCharacter(cstrp_input);\r
+ for(i = 0; i < i_max; i++){\r
+ //history entry loop\r
+ cstr_history = CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(WorkingSet.InputHistory, i));\r
+ j_max = CHNLIB_UTF8_GetStringLengthByCharacter(cstr_history);\r
+ cstrp_history = cstr_history;\r
+ \r
+ for(j = 0; j < j_max; j++){\r
+ //history character loop\r
+ templength = CHNLIB_UTF8_CompareString_LeftHand(cstrp_history, cstrp_input);\r
+ if(templength > candidatelength && templength != cstrp_input_length){\r
+ //前方一致の長さが、これまで見つかった単語よりも長く、かつ入力文字列の検索部分の全長ではない場合、\r
+ //単語の候補とする。\r
+ candidatelength = templength;\r
}\r
+ CHNLIB_UTF8_GetNextUnicodeOfCharacter(cstrp_history, &cstrp_history);\r
}\r
- if(candidatelength > 0){\r
- //AI_Memory_AddRootWordData(CHNLIB_String_ExtractByLength(input, k, candidatelength));\r
- CHNLIB_UIPArray_AppendLast_ProtectFromDuplication(&candidatewordlist, 0, CHNLIB_String_ExtractByLength(input, k, candidatelength), &AI_Memory_AddRootWordData_IsDuplicated);\r
- }\r
}\r
+ if(candidatelength > 0){\r
+ CHNLIB_UIPArray_AppendLast_ProtectFromDuplication(&candidatewordlist, 0, CHNLIB_String_ExtractByLength(input, CHNLIB_UTF8_GetByteSizeFromLengthByCharacter(cstr_input, 0, k - 1), CHNLIB_UTF8_GetByteSizeFromLengthByCharacter(cstrp_input, 0, candidatelength - 1)), &AI_Memory_AddRootWordData_IsDuplicated);\r
+ }\r
+ CHNLIB_UTF8_GetNextUnicodeOfCharacter(cstrp_input, &cstrp_input);\r
}\r
\r
//各候補単語が入力文字列にいくつ含まれているかをdata32に保存する。\r