Stop prepending ((\[[ to actions that end with ))/]], fix compile warning for npos, and remove unnecessary checks from sendMsg()

Users can have their actions not get broken should they end with )) or ]] without beginning OOC, while AutoOOC is enabled.
This commit is contained in:
Lirusaito
2012-02-05 14:22:52 -05:00
parent 27763d8390
commit 06837a2a77

View File

@@ -2156,59 +2156,58 @@ void LLFloaterIMPanel::sendMsg()
if (mInputEditor) mInputEditor->updateHistory(); if (mInputEditor) mInputEditor->updateHistory();
// Truncate and convert to UTF8 for transport // Truncate and convert to UTF8 for transport
std::string utf8text = wstring_to_utf8str(text); std::string utf8text = wstring_to_utf8str(text);
// Convert MU*s style poses into IRC emotes here.
if (gSavedSettings.getBOOL("AscentAllowMUpose") && utf8text.length() > 3 && utf8text[0] == ':')
{
if (utf8text[1] == '\'')
{
utf8text.replace(0, 1, "/me");
}
else if (isalpha(utf8text[1])) // Do not prevent smileys and such.
{
utf8text.replace(0, 1, "/me ");
}
}
if (utf8text.find("/ME'") == 0 || utf8text.find("/ME ") == 0) //Allow CAPSlock /me
utf8text.replace(1, 2, "me");
std::string prefix = utf8text.substr(0, 4);
if (gSavedSettings.getBOOL("AscentAutoCloseOOC") && (utf8text.length() > 1) && !mRPMode) if (gSavedSettings.getBOOL("AscentAutoCloseOOC") && (utf8text.length() > 1) && !mRPMode)
{ {
// Chalice - OOC autoclosing patch based on code by Henri Beauchamp // Chalice - OOC autoclosing patch based on code by Henri Beauchamp
int needsClosingType=0; int needsClosingType=0;
//Check if it needs the end-of-chat brackets -HgB //Check if it needs the end-of-chat brackets -HgB
if (utf8text.find("((") == 0 && utf8text.find("))") == -1) if (utf8text.find("((") == 0 && utf8text.find("))") == std::string::npos)
{ {
if(utf8text.at(utf8text.length() - 1) == ')') if(*utf8text.rbegin() == ')')
utf8text+=" "; utf8text+=" ";
utf8text+="))"; utf8text+="))";
} }
else if(utf8text.find("[[") == 0 && utf8text.find("]]") == -1) else if(utf8text.find("[[") == 0 && utf8text.find("]]") == std::string::npos)
{ {
if(utf8text.at(utf8text.length() - 1) == ']') if(*utf8text.rbegin() == ']')
utf8text+=" "; utf8text+=" ";
utf8text+="]]"; utf8text+="]]";
} }
//Check if it needs the start-of-chat brackets -HgB //Check if it needs the start-of-chat brackets -HgB
needsClosingType=0; needsClosingType=0;
if (utf8text.find("((") == -1 && utf8text.find("))") == (utf8text.length() - 2)) if (prefix != "/me " && prefix != "/me'") //Allow /me to end with )) or ]]
{ {
if(utf8text.at(0) == '(') if (utf8text.find("((") == std::string::npos && utf8text.find("))") == (utf8text.length() - 2))
utf8text.insert(0," "); {
utf8text.insert(0,"(("); if(utf8text[0] == '(')
} utf8text.insert(0," ");
else if (utf8text.find("[[") == -1 && utf8text.find("]]") == (utf8text.length() - 2)) utf8text.insert(0,"((");
{ }
if(utf8text.at(0) == '[') else if (utf8text.find("[[") == std::string::npos && utf8text.find("]]") == (utf8text.length() - 2))
utf8text.insert(0," "); {
utf8text.insert(0,"[["); if(utf8text[0] == '[')
utf8text.insert(0," ");
utf8text.insert(0,"[[");
}
} }
} }
// Convert MU*s style poses into IRC emotes here. if (mRPMode && prefix != "/me " && prefix != "/me'")
if (gSavedSettings.getBOOL("AscentAllowMUpose") && utf8text.find(":") == 0 && utf8text.length() > 3) utf8text = "[[" + utf8text + "]]";
{
if (utf8text.find(":'") == 0)
{
utf8text.replace(0, 1, "/me");
}
else if (isalpha(utf8text.at(1))) // Do not prevent smileys and such.
{
utf8text.replace(0, 1, "/me ");
}
}
if (utf8text.find("/ME'") == 0 || utf8text.find("/ME ") == 0) //Allow CAPSlock /me
{
utf8text.replace(1, 2, "me");
}
std::string prefix = utf8text.substr(0, 4);
if (prefix != "/me " && prefix != "/me'")
if (mRPMode) utf8text = "[[" + utf8text + "]]";
// [RLVa:KB] - Checked: 2011-09-17 (RLVa-1.1.4b) | Modified: RLVa-1.1.4b // [RLVa:KB] - Checked: 2011-09-17 (RLVa-1.1.4b) | Modified: RLVa-1.1.4b
if ( (gRlvHandler.hasBehaviour(RLV_BHVR_SENDIM)) || (gRlvHandler.hasBehaviour(RLV_BHVR_SENDIMTO)) ) if ( (gRlvHandler.hasBehaviour(RLV_BHVR_SENDIM)) || (gRlvHandler.hasBehaviour(RLV_BHVR_SENDIMTO)) )
{ {