From 101d0fcdfb6efcbc88e98ffb91b2074f3aee54d4 Mon Sep 17 00:00:00 2001 From: John Date: Sat, 30 Apr 2022 15:36:48 +0200 Subject: [PATCH] add optional clear flag to splitFields --- src/lib/ebus/filereader.cpp | 6 ++++-- src/lib/ebus/filereader.h | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib/ebus/filereader.cpp b/src/lib/ebus/filereader.cpp index 89a6b44d..d6c4f04f 100755 --- a/src/lib/ebus/filereader.cpp +++ b/src/lib/ebus/filereader.cpp @@ -219,8 +219,10 @@ static size_t hashFunction(const string& str) { } bool FileReader::splitFields(istream* stream, vector* row, unsigned int* lineNo, - size_t* hash, size_t* size) { - row->clear(); + size_t* hash, size_t* size, bool clear) { + if (clear) { + row->clear(); + } string line; bool quotedText = false, wasQuoted = false; ostringstream field; diff --git a/src/lib/ebus/filereader.h b/src/lib/ebus/filereader.h index d98423cb..d34a8db4 100755 --- a/src/lib/ebus/filereader.h +++ b/src/lib/ebus/filereader.h @@ -162,10 +162,11 @@ class FileReader { * @param lineNo the current line number (incremented with each line read). * @param hash optional pointer to a @a size_t value for combining the hash of the line with, or nullptr. * @param size optional pointer to a @a size_t value to add the trimmed line length to, or nullptr. + * @param clear whether to clear the fields before adding any. * @return true if there are more lines to read, false when there are no more lines left. */ static bool splitFields(istream* stream, vector* row, unsigned int* lineNo, - size_t* hash = nullptr, size_t* size = nullptr); + size_t* hash = nullptr, size_t* size = nullptr, bool clear = true); /** * Format the specified hash as 8 hex digits to the output stream.