pitrou commented on a change in pull request #11064:
URL: https://github.com/apache/arrow/pull/11064#discussion_r702911552
##########
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:
As you prefer, but I would be fine with keeping this a macro in this
case. Note there is a control flow inside the macro so you cannot turn it into
such a trivial loop.
##########
File path: cpp/src/arrow/util/value_parsing.h
##########
@@ -281,6 +371,19 @@ struct StringToUnsignedIntConverterMixin {
if (ARROW_PREDICT_FALSE(length == 0)) {
return false;
}
+ // If its starts with 0x then its hex
+ if (*s == '0' && *(s + 1) == 'x'){
Review comment:
+1
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]