| 95 | } // anonymous namespace |
| 96 | |
| 97 | bool SafeStringTo32(LiteString str, int32_t* value) { |
| 98 | SkipSpaces(&str); |
| 99 | |
| 100 | int64_t vmax = kInt32Max; |
| 101 | int sign = 1; |
| 102 | if (str.Consume("-")) { |
| 103 | sign = -1; |
| 104 | ++vmax; |
| 105 | } |
| 106 | |
| 107 | if (!isdigit(SafeFirstChar(str))) { |
| 108 | return false; |
| 109 | } |
| 110 | |
| 111 | int64_t result = 0; |
| 112 | do { |
| 113 | result = result * 10 + SafeFirstChar(str) - '0'; |
| 114 | if (result > vmax) { |
| 115 | return false; |
| 116 | } |
| 117 | str.remove_prefix(1); |
| 118 | } while (isdigit(SafeFirstChar(str))); |
| 119 | |
| 120 | SkipSpaces(&str); |
| 121 | |
| 122 | if (!str.empty()) { |
| 123 | return false; |
| 124 | } |
| 125 | |
| 126 | *value = static_cast<int32_t>(result * sign); |
| 127 | return true; |
| 128 | } |
| 129 | |
| 130 | bool SafeStringTo64(LiteString str, int64_t* value) { |
| 131 | SkipSpaces(&str); |
nothing calls this directly
no test coverage detected