diff --git a/src/common/string_util.h b/src/common/string_util.h index a0100173e..fb6ff676c 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -1,7 +1,9 @@ #pragma once -#include +#include #include +#include #include +#include #include namespace StringUtil { @@ -26,4 +28,16 @@ inline int Strcasecmp(const char* s1, const char* s2) #endif } +/// Wrapper arond std::from_chars +template +std::optional FromChars(const std::string_view str) +{ + T value; + const std::from_chars_result result = std::from_chars(str.data(), str.data() + str.length(), value); + if (result.ec != std::errc()) + return std::nullopt; + + return value; +} + } // namespace StringUtil \ No newline at end of file