diff options
Diffstat (limited to 'Swift/Controllers')
-rw-r--r-- | Swift/Controllers/Chat/ChatMessageParser.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Swift/Controllers/Chat/ChatMessageParser.cpp b/Swift/Controllers/Chat/ChatMessageParser.cpp index 1a822a1..31be451 100644 --- a/Swift/Controllers/Chat/ChatMessageParser.cpp +++ b/Swift/Controllers/Chat/ChatMessageParser.cpp @@ -105,114 +105,114 @@ namespace Swift { while (regex_search(start, text.end(), match, emoticonRegex)) { int matchIndex = 0; for (matchIndex = 1; matchIndex < static_cast<int>(match.size()); matchIndex++) { if (match[matchIndex].length() > 0) { //This is the matching subgroup break; } } std::string::const_iterator matchStart = match[matchIndex].first; std::string::const_iterator matchEnd = match[matchIndex].second; if (start != matchStart) { /* If we're skipping over plain text since the previous emoticon, record it as plain text */ newMessage.append(std::make_shared<ChatWindow::ChatTextMessagePart>(std::string(start, matchStart))); } std::shared_ptr<ChatWindow::ChatEmoticonMessagePart> emoticonPart = std::make_shared<ChatWindow::ChatEmoticonMessagePart>(); std::string matchString = match[matchIndex].str(); std::map<std::string, std::string>::const_iterator emoticonIterator = emoticons_.find(matchString); assert (emoticonIterator != emoticons_.end()); const StringPair& emoticon = *emoticonIterator; emoticonPart->imagePath = emoticon.second; emoticonPart->alternativeText = emoticon.first; newMessage.append(emoticonPart); start = matchEnd; } if (start != text.end()) { /* If there's plain text after the last emoticon, record it */ newMessage.append(std::make_shared<ChatWindow::ChatTextMessagePart>(std::string(start, text.end()))); } } - catch (std::runtime_error) { + catch (const std::runtime_error&) { /* Basically too expensive to compute the regex results and it gave up, so pass through as text */ newMessage.append(part); } } else { newMessage.append(part); } } parsedMessage.setParts(newMessage.getParts()); } return parsedMessage; } ChatWindow::ChatMessage ChatMessageParser::splitHighlight(const ChatWindow::ChatMessage& message) { auto keywordToRegEx = [](const std::string& keyword, bool matchCaseSensitive) { std::string escaped = Regex::escape(keyword); boost::regex::flag_type flags = boost::regex::normal; if (!matchCaseSensitive) { flags |= boost::regex::icase; } return boost::regex("\\b" + escaped + "\\b", flags); }; auto highlightKeywordInChatMessage = [&](const ChatWindow::ChatMessage& message, const std::string& keyword, bool matchCaseSensitive, const HighlightAction& action) { ChatWindow::ChatMessage resultMessage; for (const auto& part : message.getParts()) { std::shared_ptr<ChatWindow::ChatTextMessagePart> textPart; if ((textPart = std::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(part))) { try { boost::match_results<std::string::const_iterator> match; const std::string& text = textPart->text; std::string::const_iterator start = text.begin(); while (regex_search(start, text.end(), match, keywordToRegEx(keyword, matchCaseSensitive))) { std::string::const_iterator matchStart = match[0].first; std::string::const_iterator matchEnd = match[0].second; if (start != matchStart) { /* If we're skipping over plain text since the previous emoticon, record it as plain text */ resultMessage.append(std::make_shared<ChatWindow::ChatTextMessagePart>(std::string(start, matchStart))); } std::shared_ptr<ChatWindow::ChatHighlightingMessagePart> highlightPart = std::make_shared<ChatWindow::ChatHighlightingMessagePart>(); highlightPart->text = match.str(); highlightPart->action = action; resultMessage.append(highlightPart); start = matchEnd; } if (start != text.end()) { /* If there's plain text after the last emoticon, record it */ resultMessage.append(std::make_shared<ChatWindow::ChatTextMessagePart>(std::string(start, text.end()))); } } - catch (std::runtime_error) { + catch (const std::runtime_error&) { /* Basically too expensive to compute the regex results and it gave up, so pass through as text */ resultMessage.append(part); } } else { resultMessage.append(part); } } return resultMessage; }; ChatWindow::ChatMessage parsedMessage = message; // detect mentions of own nickname HighlightAction ownMentionKeywordAction = highlightConfiguration_->ownMentionAction; ownMentionKeywordAction.setSoundFilePath(boost::optional<std::string>()); ownMentionKeywordAction.setSystemNotificationEnabled(false); if (!getNick().empty() && !highlightConfiguration_->ownMentionAction.isEmpty()) { auto nicknameHighlightedMessage = highlightKeywordInChatMessage(parsedMessage, nick_, false, ownMentionKeywordAction); auto highlightedParts = nicknameHighlightedMessage.getParts(); auto ownNicknamePart = std::find_if(highlightedParts.begin(), highlightedParts.end(), [&](std::shared_ptr<ChatWindow::ChatMessagePart>& part){ auto highlightPart = std::dynamic_pointer_cast<ChatWindow::ChatHighlightingMessagePart>(part); if (highlightPart && highlightPart->text == nick_) { return true; } return false; }); if (ownNicknamePart != highlightedParts.end()) { parsedMessage.setHighlightActionOwnMention(highlightConfiguration_->ownMentionAction); } parsedMessage.setParts(nicknameHighlightedMessage.getParts()); |