summaryrefslogtreecommitdiff
path: root/indra/newview/llautoreplace.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llautoreplace.cpp')
-rw-r--r--indra/newview/llautoreplace.cpp50
1 files changed, 18 insertions, 32 deletions
diff --git a/indra/newview/llautoreplace.cpp b/indra/newview/llautoreplace.cpp
index d71cf290d6..94773e312c 100644
--- a/indra/newview/llautoreplace.cpp
+++ b/indra/newview/llautoreplace.cpp
@@ -30,29 +30,17 @@
#include "llviewercontrol.h"
#include "llnotificationsutil.h"
-LLAutoReplace* LLAutoReplace::sInstance;
-
const char* LLAutoReplace::SETTINGS_FILE_NAME = "autoreplace.xml";
-LLAutoReplace::LLAutoReplace()
-{
-}
-
-LLAutoReplace::~LLAutoReplace()
-{
- sInstance = NULL;
-}
-
-void LLAutoReplace::autoreplaceCallback(LLUIString& inputText, S32& cursorPos)
+void LLAutoReplace::autoreplaceCallback(LLWString& inputText, S32& cursorPos)
{
static LLCachedControl<bool> perform_autoreplace(gSavedSettings, "AutoReplace");
if(perform_autoreplace)
{
S32 wordEnd = cursorPos-1;
- LLWString text = inputText.getWString();
- bool atSpace = (text[wordEnd] == ' ');
- bool haveWord = (LLWStringUtil::isPartOfWord(text[wordEnd]));
+ bool atSpace = (inputText[wordEnd] == ' ');
+ bool haveWord = (LLWStringUtil::isPartOfWord(inputText[wordEnd]));
if (atSpace || haveWord)
{
@@ -60,7 +48,7 @@ void LLAutoReplace::autoreplaceCallback(LLUIString& inputText, S32& cursorPos)
{
// find out if this space immediately follows a word
wordEnd--;
- haveWord = (LLWStringUtil::isPartOfWord(text[wordEnd]));
+ haveWord = (LLWStringUtil::isPartOfWord(inputText[wordEnd]));
}
if (haveWord)
{
@@ -68,14 +56,14 @@ void LLAutoReplace::autoreplaceCallback(LLUIString& inputText, S32& cursorPos)
std::string word;
S32 wordStart = wordEnd;
for ( S32 backOne = wordStart - 1;
- backOne >= 0 && LLWStringUtil::isPartOfWord(text[backOne]);
+ backOne >= 0 && LLWStringUtil::isPartOfWord(inputText[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 strText = std::string(inputText.begin(), inputText.end());
std::string lastWord = strText.substr(wordStart, wordEnd-wordStart+1);
std::string replacementWord( mSettings.replaceWord( lastWord ) );
@@ -89,8 +77,7 @@ void LLAutoReplace::autoreplaceCallback(LLUIString& inputText, S32& cursorPos)
LLWString strOld = utf8str_to_wstring(lastWord);
int size_change = strNew.size() - strOld.size();
- text.replace(wordStart,lastWord.length(),strNew);
- inputText = wstring_to_utf8str(text);
+ inputText.replace(wordStart,lastWord.length(),strNew);
cursorPos+=size_change;
}
}
@@ -99,16 +86,6 @@ void LLAutoReplace::autoreplaceCallback(LLUIString& inputText, S32& cursorPos)
}
}
-LLAutoReplace* LLAutoReplace::getInstance()
-{
- if(!sInstance)
- {
- sInstance = new LLAutoReplace();
- sInstance->loadFromSettings();
- }
- return sInstance;
-}
-
std::string LLAutoReplace::getUserSettingsFileName()
{
std::string path=gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "");
@@ -147,6 +124,15 @@ void LLAutoReplace::setSettings(const LLAutoReplaceSettings& newSettings)
saveToUserSettings();
}
+LLAutoReplace::LLAutoReplace()
+{
+}
+
+void LLAutoReplace::initSingleton()
+{
+ loadFromSettings();
+}
+
void LLAutoReplace::loadFromSettings()
{
std::string filename=getUserSettingsFileName();
@@ -220,7 +206,7 @@ void LLAutoReplace::saveToUserSettings()
std::string filename=getUserSettingsFileName();
llofstream file;
file.open(filename.c_str());
- LLSDSerialize::toPrettyXML(mSettings.getAsLLSD(), file);
+ LLSDSerialize::toPrettyXML(mSettings.asLLSD(), file);
file.close();
LL_INFOS("AutoReplace") << "settings saved to '" << filename << "'" << LL_ENDL;
}
@@ -801,7 +787,7 @@ LLSD LLAutoReplaceSettings::getExampleLLSD()
return example;
}
-const LLSD& LLAutoReplaceSettings::getAsLLSD()
+const LLSD& LLAutoReplaceSettings::asLLSD()
{
return mLists;
}