MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / ParseInteger

Function ParseInteger

extern/re2/re2/parse.cc:1326–1343  ·  view source on GitHub ↗

Parses a decimal integer, storing it in *np. Sets *s to span the remainder of the string.

Source from the content-addressed store, hash-verified

1324// Parses a decimal integer, storing it in *np.
1325// Sets *s to span the remainder of the string.
1326static bool ParseInteger(StringPiece* s, int* np) {
1327 if (s->empty() || !isdigit((*s)[0] & 0xFF))
1328 return false;
1329 // Disallow leading zeros.
1330 if (s->size() >= 2 && (*s)[0] == '0' && isdigit((*s)[1] & 0xFF))
1331 return false;
1332 int n = 0;
1333 int c;
1334 while (!s->empty() && isdigit(c = (*s)[0] & 0xFF)) {
1335 // Avoid overflow.
1336 if (n >= 100000000)
1337 return false;
1338 n = n*10 + c - '0';
1339 s->remove_prefix(1); // digit
1340 }
1341 *np = n;
1342 return true;
1343}
1344
1345// Parses a repetition suffix like {1,2} or {2} or {2,}.
1346// Sets *s to span the remainder of the string on success.

Callers 1

MaybeParseRepetitionFunction · 0.85

Calls 3

remove_prefixMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected