From 2ee6f67892e2c5b55a38eec30a4b7b272b4f8b3a Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Mon, 15 Aug 2022 19:16:46 -0400 Subject: [PATCH] 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 --- common/dsnlexer.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/common/dsnlexer.cpp b/common/dsnlexer.cpp index 23c63070c5..99e5668299 100644 --- a/common/dsnlexer.cpp +++ b/common/dsnlexer.cpp @@ -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() ) {