MCPcopy Create free account
hub / github.com/ablab/spades / consumeUnsignedInteger

Method consumeUnsignedInteger

ext/src/llvm/StringRef.cpp:416–462  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

414}
415
416bool llvm::consumeUnsignedInteger(StringRef &Str, unsigned Radix,
417 unsigned long long &Result) {
418 // Autosense radix if not specified.
419 if (Radix == 0)
420 Radix = GetAutoSenseRadix(Str);
421
422 // Empty strings (after the radix autosense) are invalid.
423 if (Str.empty()) return true;
424
425 // Parse all the bytes of the string given this radix. Watch for overflow.
426 StringRef Str2 = Str;
427 Result = 0;
428 while (!Str2.empty()) {
429 unsigned CharVal;
430 if (Str2[0] >= '0' && Str2[0] <= '9')
431 CharVal = Str2[0] - '0';
432 else if (Str2[0] >= 'a' && Str2[0] <= 'z')
433 CharVal = Str2[0] - 'a' + 10;
434 else if (Str2[0] >= 'A' && Str2[0] <= 'Z')
435 CharVal = Str2[0] - 'A' + 10;
436 else
437 break;
438
439 // If the parsed value is larger than the integer radix, we cannot
440 // consume any more characters.
441 if (CharVal >= Radix)
442 break;
443
444 // Add in this character.
445 unsigned long long PrevResult = Result;
446 Result = Result * Radix + CharVal;
447
448 // Check for overflow by shifting back and seeing if bits were lost.
449 if (Result / Radix < PrevResult)
450 return true;
451
452 Str2 = Str2.substr(1);
453 }
454
455 // We consider the operation a failure if no characters were consumed
456 // successfully.
457 if (Str.size() == Str2.size())
458 return true;
459
460 Str = Str2;
461 return false;
462}
463
464bool llvm::consumeSignedInteger(StringRef &Str, unsigned Radix,
465 long long &Result) {

Callers

nothing calls this directly

Calls 4

GetAutoSenseRadixFunction · 0.85
emptyMethod · 0.45
substrMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected