From 0a366c58b3cd1086418ecd3d116d65e08e7a7123 Mon Sep 17 00:00:00 2001 From: john30 Date: Sun, 6 Nov 2016 09:19:50 +0100 Subject: [PATCH] added option to skip last symbol to addAll() --- src/lib/ebus/symbol.cpp | 8 ++++++-- src/lib/ebus/symbol.h | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lib/ebus/symbol.cpp b/src/lib/ebus/symbol.cpp index 4653bbef..ae1dfe3f 100644 --- a/src/lib/ebus/symbol.cpp +++ b/src/lib/ebus/symbol.cpp @@ -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 isEscaped = str.m_unescapeState == 0; vector 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); } if (addCrc) diff --git a/src/lib/ebus/symbol.h b/src/lib/ebus/symbol.h index d71c3a47..e34b59e6 100644 --- a/src/lib/ebus/symbol.h +++ b/src/lib/ebus/symbol.h @@ -86,8 +86,9 @@ public: /** * Add all symbols from the other @a SymbolString and the calculated CRC if escaped. * @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.