From b951290955141f8bbc2e2736bc53c188d4fb5e22 Mon Sep 17 00:00:00 2001 From: Ansariel Date: Thu, 12 Nov 2015 10:12:39 +0100 Subject: [PATCH] Maintenance: More removal of code duplication - this time: processChatTypeTriggers() --- indra/newview/fsfloaternearbychat.cpp | 45 ++------------------------- indra/newview/fsfloaternearbychat.h | 1 - indra/newview/fsnearbychathub.cpp | 3 +- indra/newview/fsnearbychathub.h | 2 +- 4 files changed, 5 insertions(+), 46 deletions(-) diff --git a/indra/newview/fsfloaternearbychat.cpp b/indra/newview/fsfloaternearbychat.cpp index f729ab46e9..f736bb1746 100644 --- a/indra/newview/fsfloaternearbychat.cpp +++ b/indra/newview/fsfloaternearbychat.cpp @@ -81,16 +81,6 @@ void send_chat_from_nearby_floater(std::string utf8_out_text, EChatType type, S3 // [/RLVa:KB] void really_send_chat_from_nearby_floater(std::string utf8_out_text, EChatType type, S32 channel); -struct LLChatTypeTrigger { - std::string name; - EChatType type; -}; - -static LLChatTypeTrigger sChatTypeTriggers[] = { - { "/whisper" , CHAT_TYPE_WHISPER}, - { "/shout" , CHAT_TYPE_SHOUT} -}; - FSFloaterNearbyChat::FSFloaterNearbyChat(const LLSD& key) : LLFloater(key) ,mChatHistory(NULL) @@ -693,6 +683,7 @@ BOOL FSFloaterNearbyChat::handleKeyHere( KEY key, MASK mask ) } else if (mask == (MASK_SHIFT | MASK_CONTROL)) { + // linefeed if (!gSavedSettings.getBOOL("FSUseSingleLineChatEntry")) { if ((wstring_utf8_length(mInputEditor->getWText()) + wchar_utf8_length('\n')) > mInputEditor->getMaxTextLength()) @@ -746,38 +737,6 @@ void FSFloaterNearbyChat::reshapeChatLayoutPanel() mChatLayoutPanel->reshape(mChatLayoutPanel->getRect().getWidth(), mInputEditor->getRect().getHeight() + mInputEditorPad, FALSE); } -EChatType FSFloaterNearbyChat::processChatTypeTriggers(EChatType type, std::string &str) -{ - U32 length = str.length(); - S32 cnt = sizeof(sChatTypeTriggers) / sizeof(*sChatTypeTriggers); - - for (S32 n = 0; n < cnt; n++) - { - if (length >= sChatTypeTriggers[n].name.length()) - { - std::string trigger = str.substr(0, sChatTypeTriggers[n].name.length()); - - if (!LLStringUtil::compareInsensitive(trigger, sChatTypeTriggers[n].name)) - { - U32 trigger_length = sChatTypeTriggers[n].name.length(); - - // It's to remove space after trigger name - if (length > trigger_length && str[trigger_length] == ' ') - trigger_length++; - - str = str.substr(trigger_length, length); - - if (CHAT_TYPE_NORMAL == type) - return sChatTypeTriggers[n].type; - else - break; - } - } - } - - return type; -} - void FSFloaterNearbyChat::sendChat( EChatType type ) { if (mInputEditor) @@ -839,7 +798,7 @@ void FSFloaterNearbyChat::sendChat( EChatType type ) nType = type; } - type = processChatTypeTriggers(nType, utf8_revised_text); + type = FSNearbyChat::processChatTypeTriggers(nType, utf8_revised_text); if (!utf8_revised_text.empty() && cmd_line_chat(utf8_revised_text, type)) { diff --git a/indra/newview/fsfloaternearbychat.h b/indra/newview/fsfloaternearbychat.h index 0b66c0b29d..bd4590ec43 100644 --- a/indra/newview/fsfloaternearbychat.h +++ b/indra/newview/fsfloaternearbychat.h @@ -111,7 +111,6 @@ protected: void onChatBoxCommit(); void onChatTypeChanged(); - EChatType processChatTypeTriggers(EChatType type, std::string &str); void reshapeFloater(bool collapse); void reshapeChatLayoutPanel(); diff --git a/indra/newview/fsnearbychathub.cpp b/indra/newview/fsnearbychathub.cpp index f81ca7400d..554d29d71d 100644 --- a/indra/newview/fsnearbychathub.cpp +++ b/indra/newview/fsnearbychathub.cpp @@ -65,7 +65,7 @@ struct LLChatTypeTrigger { static LLChatTypeTrigger sChatTypeTriggers[] = { { "/whisper" , CHAT_TYPE_WHISPER}, - { "/shout" , CHAT_TYPE_SHOUT} + { "/shout" , CHAT_TYPE_SHOUT} }; S32 FSNearbyChat::sLastSpecialChatChannel = 0; @@ -318,6 +318,7 @@ void FSNearbyChat::sendChatFromViewer(const LLWString& wtext, EChatType type, BO send_chat_from_viewer(utf8_out_text, type, channel); } +// static EChatType FSNearbyChat::processChatTypeTriggers(EChatType type, std::string &str) { U32 length = str.length(); diff --git a/indra/newview/fsnearbychathub.h b/indra/newview/fsnearbychathub.h index 9d89cbc9dd..2dac0c0bc2 100644 --- a/indra/newview/fsnearbychathub.h +++ b/indra/newview/fsnearbychathub.h @@ -57,7 +57,7 @@ public: void sendChat(LLWString text, EChatType type); static LLWString stripChannelNumber(const LLWString &mesg, S32* channel, S32* last_channel, bool* is_set); - EChatType processChatTypeTriggers(EChatType type, std::string &str); + static EChatType processChatTypeTriggers(EChatType type, std::string &str); void sendChatFromViewer(const std::string& utf8text, EChatType type, BOOL animate); void sendChatFromViewer(const LLWString& wtext, EChatType type, BOOL animate);