std::string SEXPR::AsString() Do not allow scientific notation for doubles.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/22902
This commit is contained in:
@@ -38,6 +38,7 @@ target_include_directories( sexpr PUBLIC
|
||||
|
||||
# the s-exp parser has a dep on the wxFile methods
|
||||
target_link_libraries( sexpr
|
||||
fmt::fmt
|
||||
${wxWidgets_LIBRARIES}
|
||||
)
|
||||
|
||||
|
||||
+19
-3
@@ -23,6 +23,7 @@
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <wx/debug.h>
|
||||
#include <fmt/core.h>
|
||||
|
||||
namespace SEXPR
|
||||
{
|
||||
@@ -195,9 +196,24 @@ namespace SEXPR
|
||||
}
|
||||
else if( IsDouble() )
|
||||
{
|
||||
std::stringstream out;
|
||||
out << std::setprecision( 16 ) << GetDouble();
|
||||
result += out.str();
|
||||
std::string out;
|
||||
out = fmt::format( "{:.10g}", GetDouble() );
|
||||
|
||||
// Scientific notation not allowed. So detect and change it
|
||||
if( out.find("e") != std::string::npos )
|
||||
{
|
||||
out = fmt::format( "{:.10f}", GetDouble() );
|
||||
|
||||
// remove trailing zeros
|
||||
while( !out.empty() && out[out.size() - 1] == '0' )
|
||||
out.pop_back();
|
||||
|
||||
// we may have just stripped all the zeros after the decimal
|
||||
if( out.size() > 1 && out[out.size() - 1] == '.' )
|
||||
out.pop_back();
|
||||
}
|
||||
|
||||
result += out;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user