From fc83641ede7ee7bc4e9d5dae8e7925527e3e6372 Mon Sep 17 00:00:00 2001 From: Nicky Date: Mon, 28 Nov 2011 20:11:09 +0100 Subject: [PATCH] FIRE-2250; In autocorrection process all strings as unicode so we get proper indices and length values. --- indra/llui/lllineeditor.cpp | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/indra/llui/lllineeditor.cpp b/indra/llui/lllineeditor.cpp index a258dcb57f..5e7399eecf 100644 --- a/indra/llui/lllineeditor.cpp +++ b/indra/llui/lllineeditor.cpp @@ -222,34 +222,47 @@ void LLLineEditor::autoCorrectText() S32 wordStart = 0; S32 wordEnd = mCursorPos-1; //llinfos <<"Checking Word, Cursor is at "< 0) && (' '!=text[wordEnd-1])) { wordEnd--; } + wordStart=wordEnd; + while ((wordEnd < (S32)text.length()) && (' '!=text[wordEnd] ) ) { wordEnd++; } - std::string lastTypedWord(std::string(text.begin(), - text.end()).substr(wordStart,wordEnd-wordStart)); - //llinfos << " The last typed word has been chosen, it is "<replaceWord(lastTypedWord)); + std::string strLastWord = std::string(text.begin(), text.end()); + std::string lastTypedWord = strLastWord.substr( wordStart, wordEnd-wordStart); + std::string correctedWord( LGGAutoCorrect::getInstance()->replaceWord(lastTypedWord)); + if(correctedWord!=lastTypedWord) { - int nDiff = utf8str_to_utf16str( correctedWord ).size() - utf8str_to_utf16str( lastTypedWord ).size(); - std::string regText(mText); + LLWString strNew = utf8str_to_wstring( correctedWord ); + LLWString strOld = utf8str_to_wstring( lastTypedWord ); + int nDiff = strNew.size() - strOld.size(); + //int wordStart = regText.find(lastTypedWord); - regText.replace(wordStart,lastTypedWord.length(),correctedWord); - mText=regText; + text.replace(wordStart,lastTypedWord.length(),strNew); + mText = wstring_to_utf8str(text); mCursorPos+=nDiff; } }