diff options
| author | Pierre Bourdon <delroth@gmail.com> | 2017-09-18 05:04:11 +0200 |
|---|---|---|
| committer | Pierre Bourdon <delroth@gmail.com> | 2017-09-18 05:04:11 +0200 |
| commit | 43f067c6e16cbad428e2d5ec11cd3094fb14a868 (patch) | |
| tree | 6904e008c3f87634cc7b6f3fcdfd42cc7a60c19b /Source/Core/Common/StringUtil.cpp | |
| parent | c50848be21bd0fd85f88548bca4f5ba7ab2e6924 (diff) | |
StringUtil: support TryParse(u16*)
Diffstat (limited to 'Source/Core/Common/StringUtil.cpp')
| -rw-r--r-- | Source/Core/Common/StringUtil.cpp | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index 03e6bb3d45..445224757b 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -226,25 +226,27 @@ std::string StripQuotes(const std::string& s) return s; } -bool TryParse(const std::string& str, u32* const output) +bool TryParse(const std::string& str, u16* const output) { - char* endptr = nullptr; - - // Reset errno to a value other than ERANGE - errno = 0; - - unsigned long value = strtoul(str.c_str(), &endptr, 0); + u64 value; + if (!TryParse(str, &value)) + return false; - if (!endptr || *endptr) + if (value >= 0x10000ull && value <= 0xFFFFFFFFFFFF0000ull) return false; - if (errno == ERANGE) + *output = static_cast<u16>(value); + return true; +} + +bool TryParse(const std::string& str, u32* const output) +{ + u64 value; + if (!TryParse(str, &value)) return false; -#if ULONG_MAX > UINT_MAX if (value >= 0x100000000ull && value <= 0xFFFFFFFF00000000ull) return false; -#endif *output = static_cast<u32>(value); return true; |
