| 414 | } |
| 415 | |
| 416 | bool 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 | |
| 464 | bool llvm::consumeSignedInteger(StringRef &Str, unsigned Radix, |
| 465 | long long &Result) { |
nothing calls this directly
no test coverage detected