diff options
author | Oz Linden <oz@lindenlab.com> | 2012-05-26 06:44:59 -0400 |
---|---|---|
committer | Oz Linden <oz@lindenlab.com> | 2012-05-26 06:44:59 -0400 |
commit | 46efa1b0b6c5d4eddfef2721085406c8776ff06d (patch) | |
tree | 8a658750d1c40fc5ec8b84aadc7d87800a4eafa3 /indra | |
parent | 6075badea0dbfe0eab451913a54bb729a498c39b (diff) |
storm-1738: clarify word recognition code
Diffstat (limited to 'indra')
-rw-r--r-- | indra/newview/llautoreplace.cpp | 77 |
1 files changed, 40 insertions, 37 deletions
diff --git a/indra/newview/llautoreplace.cpp b/indra/newview/llautoreplace.cpp index 32cd7d2ae3..a4a08daf27 100644 --- a/indra/newview/llautoreplace.cpp +++ b/indra/newview/llautoreplace.cpp @@ -48,53 +48,56 @@ void LLAutoReplace::autoreplaceCallback(LLUIString& inputText, S32& cursorPos) static LLCachedControl<bool> perform_autoreplace(gSavedSettings, "AutoReplace"); if(perform_autoreplace) { - S32 wordStart = 0; S32 wordEnd = cursorPos-1; - - if(wordEnd < 1) - { - return; - } - LLWString text = inputText.getWString(); - if(text.size()<1) - { - return; - } - if(LLWStringUtil::isPartOfWord(text[wordEnd])) - { - return;//we only check on word breaks - } + bool atSpace = (text[wordEnd] == ' '); + bool haveWord = (LLWStringUtil::isPartOfWord(text[wordEnd])); - wordEnd--; - if ( LLWStringUtil::isPartOfWord(text[wordEnd]) ) + if (atSpace || haveWord) { - while ((wordEnd > 0) && (' ' != text[wordEnd-1])) + if (atSpace) { + // find out if this space immediately follows a word wordEnd--; + haveWord = (LLWStringUtil::isPartOfWord(text[wordEnd])); } - - wordStart=wordEnd; - - while ((wordEnd < (S32)text.length()) && (' ' != text[wordEnd])) - { - wordEnd++; - } - - std::string strLastWord = std::string(text.begin(), text.end()); - std::string lastTypedWord = strLastWord.substr(wordStart, wordEnd-wordStart); - std::string replacedWord( mSettings.replaceWord(lastTypedWord) ); - - if(replacedWord != lastTypedWord) + if (haveWord) { - LLWString strNew = utf8str_to_wstring(replacedWord); - LLWString strOld = utf8str_to_wstring(lastTypedWord); - int nDiff = strNew.size() - strOld.size(); + std::string word; + S32 wordStart = wordEnd; + for ( S32 backOne = wordStart - 1; + backOne >= 0 && LLWStringUtil::isPartOfWord(text[backOne]); + backOne-- + ) + { + wordStart--; // walk wordStart back to the beginning of the word + } + LL_DEBUGS("AutoReplace")<<"wordStart: "<<wordStart<<" wordEnd: "<<wordEnd<<LL_ENDL; + std::string strText = std::string(text.begin(), text.end()); + std::string lastWord = strText.substr(wordStart, wordEnd-wordStart+1); + std::string replacementWord( mSettings.replaceWord( lastWord ) ); - text.replace(wordStart,lastTypedWord.length(),strNew); - inputText = wstring_to_utf8str(text); - cursorPos+=nDiff; + if ( replacementWord != lastWord ) + { + // The last word is one for which we have a replacement + if (atSpace) + { + // replace the last word in the input + LLWString strNew = utf8str_to_wstring(replWord); + LLWString strOld = utf8str_to_wstring(lastWord); + int size_change = strNew.size() - strOld.size(); + + text.replace(wordStart,lastWord.length(),strNew); + inputText = wstring_to_utf8str(text); + cursorPos+=size_change; + } + else + { + // @TODO display replacement as tooltip? + LL_DEBUGS("AutoReplace")<<"tooltip: '"<<lastWord<<"' -> '"<<replWord<<"'"<<LL_ENDL; + } + } } } } |