martinzink commented on code in PR #1543:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1543#discussion_r1155849368
##########
libminifi/include/utils/TimeUtil.h:
##########
@@ -201,38 +203,17 @@ std::optional<TargetDuration>
cast_to_matching_unit(std::string& unit, const int
((result = cast_if_unit_matches<TargetDuration, T>(unit, value)) || ...);
return result;
}
-
-inline bool get_unit_and_value(const std::string& input, std::string& unit,
int64_t& value) {
- const char* begin = input.c_str();
- char *end;
- errno = 0;
- value = std::strtoll(begin, &end, 0);
- if (end == begin || errno == ERANGE) {
- return false;
- }
-
- if (end[0] == '\0') {
- return false;
- }
-
- while (*end == ' ') {
- // Skip the spaces
- end++;
- }
- unit = std::string(end);
- std::transform(unit.begin(), unit.end(), unit.begin(), ::tolower);
- return true;
-}
-
} // namespace details
template<class TargetDuration>
std::optional<TargetDuration> StringToDuration(const std::string& input) {
std::string unit;
int64_t value;
- if (!details::get_unit_and_value(input, unit, value))
+ if (!StringUtils::splitToUnitAndValue(input, unit, value))
return std::nullopt;
+ std::transform(unit.begin(), unit.end(), unit.begin(), ::tolower);
Review Comment:
good idea, changed it in
https://github.com/apache/nifi-minifi-cpp/pull/1543/commits/64c5975e3fda0911820465778fa4d73f16d12002#diff-4a76905d55704437ae0a7a4ee434a73f057c105c97bdf8756f5747b4fbc65e9fR216
--
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]