本文整理汇总了C++中LLWString::replace方法的典型用法代码示例。如果您正苦于以下问题:C++ LLWString::replace方法的具体用法?C++ LLWString::replace怎么用?C++ LLWString::replace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LLWString
的用法示例。
在下文中一共展示了LLWString::replace方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: autoreplaceCallback
void LLAutoReplace::autoreplaceCallback(LLUIString& 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]));
if (atSpace || haveWord)
{
if (atSpace && wordEnd > 0)
{
// find out if this space immediately follows a word
wordEnd--;
haveWord = (LLWStringUtil::isPartOfWord(text[wordEnd]));
}
if (haveWord)
{
// wordEnd points to the end of a word, now find the start of the word
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 ) );
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(replacementWord);
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;
}
}
}
}
}
}