From 46efa1b0b6c5d4eddfef2721085406c8776ff06d Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Sat, 26 May 2012 06:44:59 -0400 Subject: storm-1738: clarify word recognition code --- indra/newview/llautoreplace.cpp | 77 +++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 37 deletions(-) (limited to 'indra') 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 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: "< '"<