added option to skip last symbol to addAll()

This commit is contained in:
john30
2016-11-06 09:19:50 +01:00
parent 726b9ecfeb
commit 0a366c58b3
2 changed files with 8 additions and 3 deletions
+6 -2
View File
@@ -47,12 +47,16 @@ static const unsigned char CRC_LOOKUP_TABLE[] =
}; };
void SymbolString::addAll(const SymbolString& str) void SymbolString::addAll(const SymbolString& str, bool skipLastSymbol)
{ {
bool addCrc = m_unescapeState == 0; bool addCrc = m_unescapeState == 0;
bool isEscaped = str.m_unescapeState == 0; bool isEscaped = str.m_unescapeState == 0;
vector<unsigned char> data = str.m_data; vector<unsigned char> data = str.m_data;
for (size_t i = 0; i < data.size(); i++) { size_t end = data.size();
if (end>0 && skipLastSymbol) {
end--;
}
for (size_t i = 0; i < end; i++) {
push_back(data[i], isEscaped, addCrc); push_back(data[i], isEscaped, addCrc);
} }
if (addCrc) if (addCrc)
+2 -1
View File
@@ -86,8 +86,9 @@ public:
/** /**
* Add all symbols from the other @a SymbolString and the calculated CRC if escaped. * Add all symbols from the other @a SymbolString and the calculated CRC if escaped.
* @param str the @a SymbolString to copy from. * @param str the @a SymbolString to copy from.
* @param skipLastSymbol whether to skip the last symbol (probably the CRC).
*/ */
void addAll(const SymbolString& str); void addAll(const SymbolString& str, const bool skipLastSymbol=false);
/** /**
* Parse the escaped or unescaped hex @a string, add all symbols, and add the calculated CRC if escaped. * Parse the escaped or unescaped hex @a string, add all symbols, and add the calculated CRC if escaped.