edponce commented on a change in pull request #11064: URL: https://github.com/apache/arrow/pull/11064#discussion_r700690054
########## File path: cpp/src/arrow/util/value_parsing.h ########## @@ -273,6 +273,96 @@ inline bool ParseUnsigned(const char* s, size_t length, uint64_t* out) { #undef PARSE_UNSIGNED_ITERATION #undef PARSE_UNSIGNED_ITERATION_LAST +#define PARSE_HEX_ITERATION(C_TYPE) \ + if (length > 0) { \ + char val = *s; \ + s++; \ + result = static_cast<C_TYPE>(result << 4); \ + length--; \ + if (val >= '0' && val <= '9'){ \ + result = static_cast<C_TYPE>(result | (val -'0')); \ + } else if (val >= 'A' && val <= 'F'){ \ + result = static_cast<C_TYPE>(result | (val -'A' + 10)); \ + } else if (val >= 'a' && val <= 'f'){ \ + result = static_cast<C_TYPE>(result | (val -'a' + 10)); \ + } else { \ + /* Non-digit */ \ + return false; \ + } \ + } else { \ + break; \ + } + + +inline bool ParseHex(const char* s, size_t length, uint8_t* out) { + uint8_t result = 0; Review comment: Instead of having multiple function for each type, I suggest to use templates and given that each function is conceptually doing the same operation but different number of times based on the output data type width, use a for-loop instead. ```c++ template <typename T> inline bool ParseHex(...) { ... for (int i = 0; i < sizeof(T) * 2; ++i) { ParseHexIteration<T>(result); } ... } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org