add optional allowIncomplete to parseSignedInt()

This commit is contained in:
John
2021-11-20 09:15:09 +01:00
parent 1354b94d9e
commit efa18923a9
2 changed files with 4 additions and 3 deletions
+2 -2
View File
@@ -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;
}
+2 -1
View File
@@ -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.