summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2017-06-20 20:15:25 (GMT)
committerKevin Smith <kevin.smith@isode.com>2017-06-21 08:29:48 (GMT)
commit83fb5ae3da2e5e690a3eafae99f6cd0cb59a2496 (patch)
treeb2924f4079410642885681d53b1295e5d6125347
parenta507a88a189bb603c9f2d686c9c8dafca49c053d (diff)
downloadswift-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
-rw-r--r--Sluift/ElementConvertors/DOMElementConvertor.cpp2
-rw-r--r--Swift/Controllers/Chat/ChatMessageParser.cpp4
-rw-r--r--Swiften/Parser/BOSHBodyExtractor.cpp2
3 files changed, 4 insertions, 4 deletions
diff --git a/Sluift/ElementConvertors/DOMElementConvertor.cpp b/Sluift/ElementConvertors/DOMElementConvertor.cpp
index 72474bb..b957686 100644
--- a/Sluift/ElementConvertors/DOMElementConvertor.cpp
+++ b/Sluift/ElementConvertors/DOMElementConvertor.cpp
@@ -158,44 +158,44 @@ namespace {
DOMElementConvertor::DOMElementConvertor() {
}
DOMElementConvertor::~DOMElementConvertor() {
}
std::shared_ptr<Element> DOMElementConvertor::convertFromLua(lua_State* L, int index, const std::string& type) {
if (!lua_istable(L, index) || type != "dom") {
return std::shared_ptr<Payload>();
}
return std::make_shared<RawXMLPayload>(serializeElement(L).c_str());
}
boost::optional<std::string> DOMElementConvertor::convertToLua(
lua_State* L, std::shared_ptr<Element> element) {
// Serialize payload to XML
std::shared_ptr<Payload> payload = std::dynamic_pointer_cast<Payload>(element);
if (!payload) {
return boost::optional<std::string>();
}
PayloadSerializer* serializer = serializers.getPayloadSerializer(payload);
assert(serializer);
std::string serializedPayload = serializer->serialize(payload);
lua_newtable(L);
// Parse the payload again
ParserClient parserClient(L);
- std::shared_ptr<XMLParser> parser(std::move(parsers.createXMLParser(&parserClient)));
+ std::shared_ptr<XMLParser> parser(parsers.createXMLParser(&parserClient));
bool result = parser->parse(serializedPayload);
assert(result);
// There can only be one element, so stripping the list
lua_pushnil(L);
lua_next(L, -2);
Lua::registerTableToString(L, -1);
lua_replace(L, -3);
lua_settop(L, -2);
return std::string("dom");
}
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());
diff --git a/Swiften/Parser/BOSHBodyExtractor.cpp b/Swiften/Parser/BOSHBodyExtractor.cpp
index 803f16a..c45d338 100644
--- a/Swiften/Parser/BOSHBodyExtractor.cpp
+++ b/Swiften/Parser/BOSHBodyExtractor.cpp
@@ -99,42 +99,42 @@ BOSHBodyExtractor::BOSHBodyExtractor(XMLParserFactory* parserFactory, const Byte
ByteArray::const_reverse_iterator j = data.rbegin();
if (!endElementSeen) {
while (isWhitespace(*j) && j < data.rend()) {
++j;
}
if (j == data.rend() || *j != '>') {
return;
}
++j;
while (j < data.rend() && isWhitespace(*j)) {
++j;
}
if (std::distance(j, data.rend()) < 6 || *(j+5) != '<' || *(j+4) != '/' || *(j+3) != 'b' || *(j+2) != 'o' || *(j+1) != 'd' || *j != 'y') {
return;
}
j += 6;
}
body = BOSHBody();
if (!endElementSeen) {
body->content = std::string(
reinterpret_cast<const char*>(vecptr(data) + std::distance(data.begin(), i)),
boost::numeric_cast<size_t>(std::distance(i, j.base())));
}
// Parse the body element
BOSHBodyParserClient parserClient(this);
- std::shared_ptr<XMLParser> parser(std::move(parserFactory->createXMLParser(&parserClient)));
+ std::shared_ptr<XMLParser> parser(parserFactory->createXMLParser(&parserClient));
if (!parser->parse(std::string(
reinterpret_cast<const char*>(vecptr(data)),
boost::numeric_cast<size_t>(std::distance(data.begin(), i))))) {
/* TODO: This needs to be only validating the BOSH <body> element, so that XMPP parsing errors are caught at
the correct higher layer */
body = boost::optional<BOSHBody>();
return;
}
}
}