In file included from adb_utils.cpp:19: adb/adb_utils.h:19:10: fatal error: 'charconv' file not found #include ^~~~~~~~~~ --- adb/adb_utils.h.orig 2019-10-18 00:22:21 UTC +++ adb/adb_utils.h @@ -16,7 +16,6 @@ #pragma once -#include #include #include #include @@ -113,17 +112,33 @@ inline std::string_view StripTrailingNulls(std::string // Base-10 stroll on a string_view. template inline bool ParseUint(T* result, std::string_view str, std::string_view* remaining = nullptr) { - T value; - const auto res = std::from_chars(str.begin(), str.end(), value); - if (res.ec != std::errc{}) { + if (str.empty() || !isdigit(str[0])) { return false; } - if (res.ptr != str.end() && !remaining) { - return false; + + T value = 0; + std::string_view::iterator it; + constexpr T max = std::numeric_limits::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) { + return false; + } + + value += digit; } + *result = value; if (remaining) { - *remaining = std::string_view(res.ptr, str.end() - res.ptr); + *remaining = str.substr(it - str.begin()); + } else { + return it == str.end(); } - *result = value; + return true; }