| 307 | |
| 308 | template <typename T> |
| 309 | bool ParseHex(const char* s, size_t length, T* out) { |
| 310 | // lets make sure that the length of the string is not too big |
| 311 | if (!ARROW_PREDICT_TRUE(sizeof(T) * 2 >= length && length > 0)) { |
| 312 | return false; |
| 313 | } |
| 314 | T result = 0; |
| 315 | for (size_t i = 0; i < length; i++) { |
| 316 | result = static_cast<T>(result << 4); |
| 317 | if (s[i] >= '0' && s[i] <= '9') { |
| 318 | result = static_cast<T>(result | (s[i] - '0')); |
| 319 | } else if (s[i] >= 'A' && s[i] <= 'F') { |
| 320 | result = static_cast<T>(result | (s[i] - 'A' + 10)); |
| 321 | } else if (s[i] >= 'a' && s[i] <= 'f') { |
| 322 | result = static_cast<T>(result | (s[i] - 'a' + 10)); |
| 323 | } else { |
| 324 | /* Non-digit */ |
| 325 | return false; |
| 326 | } |
| 327 | } |
| 328 | *out = result; |
| 329 | return true; |
| 330 | } |
| 331 | |
| 332 | template <class ARROW_TYPE> |
| 333 | struct StringToUnsignedIntConverterMixin { |