diff options
author | Kevin Smith <git@kismith.co.uk> | 2017-06-20 20:15:25 (GMT) |
---|---|---|
committer | Kevin Smith <kevin.smith@isode.com> | 2017-06-21 08:29:48 (GMT) |
commit | 83fb5ae3da2e5e690a3eafae99f6cd0cb59a2496 (patch) | |
tree | b2924f4079410642885681d53b1295e5d6125347 /Swift/Controllers/Chat/ChatMessageParser.cpp | |
parent | a507a88a189bb603c9f2d686c9c8dafca49c053d (diff) | |
download | swift-83fb5ae3da2e5e690a3eafae99f6cd0cb59a2496.zip swift-83fb5ae3da2e5e690a3eafae99f6cd0cb59a2496.tar.bz2 |
Fix compiler warnings
Both catching polymorphic base classes by value and explicitly moving things
preventing return value optimization.
Test-Information:
Compiles on macOS with latest xcode with allow_warnings=False and unit
tests pass
Change-Id: Ibdc67f4f2019f85f14635df2a3ff06bddbb8e2b6
Diffstat (limited to 'Swift/Controllers/Chat/ChatMessageParser.cpp')
-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()); |