Loading adb/adb_utils.h +8 −23 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ #pragma once #include <charconv> #include <condition_variable> #include <mutex> #include <string> Loading Loading @@ -112,33 +113,17 @@ inline std::string_view StripTrailingNulls(std::string_view str) { // Base-10 stroll on a string_view. template <typename T> inline bool ParseUint(T* result, std::string_view str, std::string_view* remaining = nullptr) { if (str.empty() || !isdigit(str[0])) { T value; const auto res = std::from_chars(str.begin(), str.end(), value); if (res.ec != std::errc{}) { return false; } T value = 0; std::string_view::iterator it; constexpr T max = std::numeric_limits<T>::max(); for (it = str.begin(); it != str.end() && isdigit(*it); ++it) { if (value > max / 10) { return false; } value *= 10; T digit = *it - '0'; if (value > max - digit) { if (res.ptr != str.end() && !remaining) { return false; } value += digit; } *result = value; if (remaining) { *remaining = str.substr(it - str.begin()); } else { return it == str.end(); *remaining = std::string_view(res.ptr, str.end() - res.ptr); } *result = value; return true; } Loading
adb/adb_utils.h +8 −23 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ #pragma once #include <charconv> #include <condition_variable> #include <mutex> #include <string> Loading Loading @@ -112,33 +113,17 @@ inline std::string_view StripTrailingNulls(std::string_view str) { // Base-10 stroll on a string_view. template <typename T> inline bool ParseUint(T* result, std::string_view str, std::string_view* remaining = nullptr) { if (str.empty() || !isdigit(str[0])) { T value; const auto res = std::from_chars(str.begin(), str.end(), value); if (res.ec != std::errc{}) { return false; } T value = 0; std::string_view::iterator it; constexpr T max = std::numeric_limits<T>::max(); for (it = str.begin(); it != str.end() && isdigit(*it); ++it) { if (value > max / 10) { return false; } value *= 10; T digit = *it - '0'; if (value > max - digit) { if (res.ptr != str.end() && !remaining) { return false; } value += digit; } *result = value; if (remaining) { *remaining = str.substr(it - str.begin()); } else { return it == str.end(); *remaining = std::string_view(res.ptr, str.end() - res.ptr); } *result = value; return true; }