edponce commented on a change in pull request #11161:
URL: https://github.com/apache/arrow/pull/11161#discussion_r709506553



##########
File path: cpp/src/arrow/compute/kernels/scalar_cast_test.cc
##########
@@ -1485,51 +1485,57 @@ TEST(Cast, StringToBoolean) {
 TEST(Cast, StringToInt) {
   for (auto string_type : {utf8(), large_utf8()}) {
     for (auto signed_type : {int8(), int16(), int32(), int64()}) {
-      CheckCast(ArrayFromJSON(string_type, R"(["0", null, "127", "-1", "0"])"),
-                ArrayFromJSON(signed_type, "[0, null, 127, -1, 0]"));
+      CheckCast(
+          ArrayFromJSON(string_type, R"(["0", null, "127", "-1", "0", "0x0", 
"0x7F"])"),
+          ArrayFromJSON(signed_type, "[0, null, 127, -1, 0, 0, 127]"));

Review comment:
       Add a test case for hex with negative sign (eg., `-0x34`) and another 
for multiple prefixed zeros (eg., `00000x7f`).

##########
File path: cpp/src/arrow/util/value_parsing.h
##########
@@ -281,6 +305,16 @@ struct StringToUnsignedIntConverterMixin {
     if (ARROW_PREDICT_FALSE(length == 0)) {
       return false;
     }
+    // If it starts with 0x then its hex
+    if (length > 2 && s[0] == '0' && ((s[1] == 'x') || (s[1] == 'X'))) {
+      length -= 2;
+      s += 2;
+
+      if (!ARROW_PREDICT_TRUE(ParseHex(s, length, out))) {
+        return false;
+      }
+      return true;

Review comment:
       Simplify to `return ARROW_PREDICT_TRUE(ParseHex(s, length, out));`.




-- 
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]


Reply via email to