X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcommon%2Fircdecoder.cpp;h=5eb0e6d1f4417ba577aa4634abfb6a036323e7a4;hb=2491fb92519912fa2169fb9d7dbc631a03bf5570;hp=d51ed553ad048cbf3dea7b4eca75967627c4f6e6;hpb=53e50ab66a5b3fa00282545ebc22ce3433ecf42b;p=quassel.git diff --git a/src/common/ircdecoder.cpp b/src/common/ircdecoder.cpp index d51ed553..5eb0e6d1 100644 --- a/src/common/ircdecoder.cpp +++ b/src/common/ircdecoder.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2019 by the Quassel Project * + * Copyright (C) 2005-2020 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -54,25 +54,18 @@ QString IrcDecoder::parseTagValue(const QString& value) result.append(*it); } escaped = false; - } else if (it->unicode() == '\\') { + } + else if (it->unicode() == '\\') { escaped = true; - } else { + } + else { result.append(*it); } } return result; } -/** - * Extracts a space-delimited fragment from an IRC message - * @param raw Raw Message - * @param start Current index into the message, will be advanced automatically - * @param end End of fragment, if already known. Default is -1, in which case it will be set to the next whitespace - * character or the end of the string - * @param prefix Required prefix. Default is 0. If set, this only parses a fragment if it starts with the given prefix. - * @return Fragment - */ -QByteArray extractFragment(const QByteArray& raw, int& start, int end = -1, char prefix = 0) +QByteArray IrcDecoder::extractFragment(const QByteArray& raw, int& start, int end, char prefix) { // Try to set find the end of the space-delimited fragment if (end == -1) { @@ -100,12 +93,7 @@ QByteArray extractFragment(const QByteArray& raw, int& start, int end = -1, char return fragment; } -/** - * Skips empty parts in the message - * @param raw Raw Message - * @param start Current index into the message, will be advanced automatically - */ -void skipEmptyParts(const QByteArray& raw, int& start) +void IrcDecoder::skipEmptyParts(const QByteArray& raw, int& start) { while (start < raw.length() && raw[start] == ' ') { start++; @@ -139,9 +127,15 @@ QHash IrcDecoder::parseTags(const std::function splitByVendorAndKey = rawKey.split('/'); - if (!splitByVendorAndKey.isEmpty()) key.key = splitByVendorAndKey.takeLast(); - if (!splitByVendorAndKey.isEmpty()) key.vendor = splitByVendorAndKey.takeLast(); + + int splitIndex = rawKey.lastIndexOf('/'); + if (splitIndex > 0 && splitIndex + 1 < rawKey.length()) { + key.key = rawKey.mid(splitIndex + 1); + key.vendor = rawKey.left(splitIndex); + } + else { + key.key = rawKey; + } tags[key] = parseTagValue(rawValue); } return tags; @@ -169,7 +163,12 @@ QByteArray IrcDecoder::parseParameter(const QByteArray& raw, int& start) } } -void IrcDecoder::parseMessage(const std::function& decode, const QByteArray& rawMsg, QHash& tags, QString& prefix, QString& command, QList& parameters) +void IrcDecoder::parseMessage(const std::function& decode, + const QByteArray& rawMsg, + QHash& tags, + QString& prefix, + QString& command, + QList& parameters) { int start = 0; skipEmptyParts(rawMsg, start); @@ -184,7 +183,6 @@ void IrcDecoder::parseMessage(const std::function& d QByteArray param = parseParameter(rawMsg, start); skipEmptyParts(rawMsg, start); params.append(param); - } parameters = params; }