MCPcopy Create free account
hub / github.com/couchbase/fleece / _parseUInt

Function _parseUInt

Fleece/Support/NumConversion.cc:25–46  ·  view source on GitHub ↗

subroutine that parses only digits

Source from the content-addressed store, hash-verified

23
24 // subroutine that parses only digits
25 static bool _parseUInt(const char *str NONNULL, uint64_t &result, bool allowTrailing) {
26 uint64_t n = 0;
27 if (!isdigit(*str))
28 return false;
29 while (isdigit(*str)) {
30 int digit = (*str++ - '0');
31 if (_usuallyFalse(n > UINT64_MAX / 10))
32 return false;
33 n *= 10;
34 if (_usuallyFalse(n > UINT64_MAX - digit))
35 return false;
36 n += digit;
37 }
38 if (!allowTrailing) {
39 while (isspace(*str))
40 ++str;
41 if (_usuallyFalse(*str != '\0'))
42 return false;
43 }
44 result = n;
45 return true;
46 }
47
48 // Unsigned version:
49 bool ParseInteger(const char *str NONNULL, uint64_t &result, bool allowTrailing) {

Callers 1

ParseIntegerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected