From efa18923a9159c13555a345bdaa5be6b50d9f37d Mon Sep 17 00:00:00 2001 From: John Date: Sat, 20 Nov 2021 09:15:09 +0100 Subject: [PATCH] add optional allowIncomplete to parseSignedInt() --- src/lib/ebus/symbol.cpp | 4 ++-- src/lib/ebus/symbol.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib/ebus/symbol.cpp b/src/lib/ebus/symbol.cpp index b97ea1da..b2a1e33d 100755 --- a/src/lib/ebus/symbol.cpp +++ b/src/lib/ebus/symbol.cpp @@ -78,12 +78,12 @@ unsigned int parseInt(const char* str, int base, unsigned int minValue, unsigned } int parseSignedInt(const char* str, int base, int minValue, int maxValue, - result_t* result, size_t* length) { + result_t* result, size_t* length, bool allowIncomplete) { char* strEnd = nullptr; long ret = strtol(str, &strEnd, base); - if (strEnd == nullptr || *strEnd != 0) { + if (strEnd == nullptr || (!allowIncomplete && *strEnd != 0)) { *result = RESULT_ERR_INVALID_NUM; // invalid value return 0; } diff --git a/src/lib/ebus/symbol.h b/src/lib/ebus/symbol.h index e69f6844..425b258a 100755 --- a/src/lib/ebus/symbol.h +++ b/src/lib/ebus/symbol.h @@ -108,10 +108,11 @@ unsigned int parseInt(const char* str, int base, unsigned int minValue, unsigned * @param maxValue the maximum resulting value. * @param result the variable in which to store an error code when parsing failed or the value is out of bounds. * @param length the optional variable in which to store the number of read characters. + * @param allowIncomplete true to allow parsing less than the complete string. * @return the parsed value. */ int parseSignedInt(const char* str, int base, int minValue, int maxValue, - result_t* result, size_t* length = nullptr); + result_t* result, size_t* length = nullptr, bool allowIncomplete = false); /** * A string of unescaped bus symbols.