Handle leading whitespace with std::from_chars

Testing the parsers, this doesn't generally happen but there was a comment about it before the changes
This commit is contained in:
Marek Roszko 2022-08-15 19:16:46 -04:00
parent ed08b0ecf6
commit 2ee6f67892
1 changed files with 12 additions and 2 deletions

View File

@ -855,9 +855,19 @@ double DSNLEXER::parseDouble()
return fval;
#else
// Use std::from_chars which is designed to be locale independent and performance oriented for data interchange
const std::string& str = CurStr();
// Offset any leading whitespace, this is one thing from_chars does not handle
int woff = 0;
while( std::isspace( str[woff] ) && woff < str.length() )
{
woff++;
}
double dval{};
const std::string& str = CurStr();
std::from_chars_result res = std::from_chars( str.data(), str.data() + str.size(), dval );
std::from_chars_result res =
std::from_chars( str.data() + woff, str.data() + str.size(), dval );
if( res.ec != std::errc() )
{