pitrou commented on code in PR #14602: URL: https://github.com/apache/arrow/pull/14602#discussion_r1018961924
########## python/pyarrow/src/arrow/python/datetime.cc: ########## @@ -38,41 +39,27 @@ namespace internal { namespace { -// Same as Regex '([+-])(0[0-9]|1[0-9]|2[0-3]):([0-5][0-9])$'. -// GCC 4.9 doesn't support regex, so handcode until support for it -// is dropped. bool MatchFixedOffset(const std::string& tz, std::string_view* sign, std::string_view* hour, std::string_view* minute) { + static const std::regex regex("^([+-])(0[0-9]|1[0-9]|2[0-3]):([0-5][0-9])$"); if (tz.size() < 5) { return false; } - const char* iter = tz.data(); - if (*iter == '+' || *iter == '-') { - *sign = std::string_view(iter, 1); - iter++; - if (tz.size() < 6) { - return false; - } - } - if ((((*iter == '0' || *iter == '1') && *(iter + 1) >= '0' && *(iter + 1) <= '9') || - (*iter == '2' && *(iter + 1) >= '0' && *(iter + 1) <= '3'))) { - *hour = std::string_view(iter, 2); - iter += 2; - } else { - return false; - } - if (*iter != ':') { + std::smatch match; + if (!std::regex_match(tz, match, regex)) { return false; } - iter++; + DCHECK_EQ(match.size(), 4); // match #0 is the whole matched sequence - if (*iter >= '0' && *iter <= '5' && *(iter + 1) >= '0' && *(iter + 1) <= '9') { - *minute = std::string_view(iter, 2); - iter += 2; - } else { - return false; - } - return iter == (tz.data() + tz.size()); + auto match_view = [&](int match_number) { + return std::string_view(&tz[match.position(match_number)], + match.length(match_number)); + }; Review Comment: That helper is a nice idea, thanks. -- 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