mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-28 11:49:06 +00:00
StringUtil: Make TryParse of floats handle comma and dot decimal separators.
This commit is contained in:
parent
7a6a4510f6
commit
0e8d4cb6ac
2 changed files with 52 additions and 56 deletions
|
@ -235,51 +235,6 @@ std::string_view StripQuotes(std::string_view s)
|
|||
return s;
|
||||
}
|
||||
|
||||
bool TryParse(const std::string& str, u16* const output)
|
||||
{
|
||||
u64 value;
|
||||
if (!TryParse(str, &value))
|
||||
return false;
|
||||
|
||||
if (value >= 0x10000ull && value <= 0xFFFFFFFFFFFF0000ull)
|
||||
return false;
|
||||
|
||||
*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 (value >= 0x100000000ull && value <= 0xFFFFFFFF00000000ull)
|
||||
return false;
|
||||
|
||||
*output = static_cast<u32>(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TryParse(const std::string& str, u64* const output)
|
||||
{
|
||||
char* end_ptr = nullptr;
|
||||
|
||||
// Set errno to a clean slate
|
||||
errno = 0;
|
||||
|
||||
u64 value = strtoull(str.c_str(), &end_ptr, 0);
|
||||
|
||||
if (end_ptr == nullptr || *end_ptr != '\0')
|
||||
return false;
|
||||
|
||||
if (errno == ERANGE)
|
||||
return false;
|
||||
|
||||
*output = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TryParse(const std::string& str, bool* const output)
|
||||
{
|
||||
float value;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue