| 128 | } |
| 129 | |
| 130 | bool SafeStringTo64(LiteString str, int64_t* value) { |
| 131 | SkipSpaces(&str); |
| 132 | |
| 133 | int64_t vlimit = kInt64Max; |
| 134 | int sign = 1; |
| 135 | if (str.Consume("-")) { |
| 136 | sign = -1; |
| 137 | vlimit = kInt64Min; |
| 138 | } |
| 139 | |
| 140 | if (!isdigit(SafeFirstChar(str))) { |
| 141 | return false; |
| 142 | } |
| 143 | |
| 144 | int64_t result = 0; |
| 145 | if (sign == 1) { |
| 146 | do { |
| 147 | int digit = SafeFirstChar(str) - '0'; |
| 148 | if ((vlimit - digit) / 10 < result) { |
| 149 | return false; |
| 150 | } |
| 151 | result = result * 10 + digit; |
| 152 | str.remove_prefix(1); |
| 153 | } while (isdigit(SafeFirstChar(str))); |
| 154 | } else { |
| 155 | do { |
| 156 | int digit = SafeFirstChar(str) - '0'; |
| 157 | if ((vlimit + digit) / 10 > result) { |
| 158 | return false; |
| 159 | } |
| 160 | result = result * 10 - digit; |
| 161 | str.remove_prefix(1); |
| 162 | } while (isdigit(SafeFirstChar(str))); |
| 163 | } |
| 164 | |
| 165 | SkipSpaces(&str); |
| 166 | if (!str.empty()) { |
| 167 | return false; |
| 168 | } |
| 169 | |
| 170 | *value = result; |
| 171 | return true; |
| 172 | } |
| 173 | |
| 174 | bool FastStringTo32(const char* str, int32_t* value) { |
| 175 | char* end = nullptr; |
nothing calls this directly
no test coverage detected