MCPcopy Create free account
hub / github.com/apache/arrow / ParseHex

Function ParseHex

cpp/src/arrow/util/value_parsing.h:309–330  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

307
308template <typename T>
309bool 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
332template <class ARROW_TYPE>
333struct StringToUnsignedIntConverterMixin {

Callers 2

ConvertMethod · 0.85
ConvertMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected