summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/windows/chatwindow.cpp59
1 files changed, 38 insertions, 21 deletions
diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp
index c434bea2f..e1afb6e5b 100644
--- a/src/gui/windows/chatwindow.cpp
+++ b/src/gui/windows/chatwindow.cpp
@@ -1240,6 +1240,39 @@ WhisperTab *ChatWindow::getWhisperTab(const std::string &nick) const
return ret;
}
+
+#define changeColor(fun) \
+ { \
+ msg = removeColors(msg); \
+ int skip = 0; \
+ const size_t sz = msg.length(); \
+ for (size_t f = 0; f < sz; f ++) \
+ { \
+ if (skip > 0) \
+ { \
+ newMsg += msg.at(f); \
+ skip --; \
+ continue; \
+ } \
+ const unsigned char ch = static_cast<unsigned char>(msg.at(f)); \
+ if (f + 2 < sz && msg.substr(f, 2) == "%%") \
+ { \
+ newMsg += msg.at(f); \
+ skip = 2; \
+ } \
+ else if (ch > 0xc0 || ch < 0x80) \
+ { \
+ newMsg += "##" + toString(fun) + msg.at(f); \
+ if (mRainbowColor > 9) \
+ mRainbowColor = 0; \
+ } \
+ else \
+ { \
+ newMsg += msg.at(f); \
+ } \
+ } \
+ }
+
std::string ChatWindow::addColors(std::string &msg)
{
// default color or chat command
@@ -1256,31 +1289,13 @@ std::string ChatWindow::addColors(std::string &msg)
switch (mChatColor)
{
case 11:
- msg = removeColors(msg);
- for (unsigned int f = 0; f < msg.length(); f ++)
- {
- newMsg += "##" + toString(mRainbowColor++) + msg.at(f);
- if (mRainbowColor > 9)
- mRainbowColor = 0;
- }
+ changeColor(mRainbowColor++)
return newMsg;
case 12:
- msg = removeColors(msg);
- for (unsigned int f = 0; f < msg.length(); f ++)
- {
- newMsg += "##" + toString(cMap[mRainbowColor++]) + msg.at(f);
- if (mRainbowColor > 9)
- mRainbowColor = 0;
- }
+ changeColor(cMap[mRainbowColor++])
return newMsg;
case 13:
- msg = removeColors(msg);
- for (unsigned int f = 0; f < msg.length(); f ++)
- {
- newMsg += "##" + toString(cMap[9-mRainbowColor++]) + msg.at(f);
- if (mRainbowColor > 9)
- mRainbowColor = 0;
- }
+ changeColor(cMap[9-mRainbowColor++])
return newMsg;
default:
break;
@@ -1290,6 +1305,8 @@ std::string ChatWindow::addColors(std::string &msg)
return std::string("##").append(toString(mChatColor - 1)).append(msg);
}
+#undef changeColor
+
void ChatWindow::autoComplete()
{
const int caretPos = mChatInput->getCaretPosition();