Fix parsing floating point values with . separator instead of ,
This commit is contained in:
@@ -392,13 +392,20 @@ int32 StringUtils::HexDigit(Char c)
|
|||||||
|
|
||||||
bool StringUtils::Parse(const Char* str, float* result)
|
bool StringUtils::Parse(const Char* str, float* result)
|
||||||
{
|
{
|
||||||
#if PLATFORM_TEXT_IS_CHAR16
|
// Convert '.' into ','
|
||||||
std::u16string u16str = str;
|
char buffer[64];
|
||||||
std::wstring wstr(u16str.begin(), u16str.end());
|
char* ptr = buffer;
|
||||||
float v = wcstof(wstr.c_str(), nullptr);
|
char* end = buffer + ARRAY_COUNT(buffer);
|
||||||
#else
|
while (str && *str && ptr != end)
|
||||||
float v = wcstof(str, nullptr);
|
{
|
||||||
#endif
|
Char c = *str++;
|
||||||
|
if (c == '.')
|
||||||
|
c = ',';
|
||||||
|
*ptr++ = (char)c;
|
||||||
|
}
|
||||||
|
*ptr = 0;
|
||||||
|
|
||||||
|
float v = (float)atof(buffer);
|
||||||
*result = v;
|
*result = v;
|
||||||
if (v == 0)
|
if (v == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user