From b9b540faffa9bae81ee6a4277fa8414aa8bcc54d Mon Sep 17 00:00:00 2001 From: Alex Fabijanic Date: Fri, 25 Jun 2021 21:03:28 +0200 Subject: [PATCH] fix(NumericString): Bug in NumericString with decSep != '.' #3159 --- Foundation/src/NumericString.cpp | 5 +++-- Foundation/testsuite/src/StringTest.cpp | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Foundation/src/NumericString.cpp b/Foundation/src/NumericString.cpp index 0add9aa985..2d932e0da2 100644 --- a/Foundation/src/NumericString.cpp +++ b/Foundation/src/NumericString.cpp @@ -16,7 +16,8 @@ // +++ double conversion +++ -#define double_conversion poco_double_conversion // don't collide with standalone double_conversion library +// don't collide with standalone double_conversion library +#define double_conversion poco_double_conversion #define UNIMPLEMENTED poco_bugcheck #include "diy-fp.cc" #include "cached-powers.cc" @@ -50,7 +51,7 @@ void pad(std::string& str, int precision, int width, char prefix = ' ', char dec std::string::size_type decSepPos = str.find(decSep); if (decSepPos == std::string::npos) { - str.append(1, '.'); + str.append(1, decSep); decSepPos = str.size() - 1; } diff --git a/Foundation/testsuite/src/StringTest.cpp b/Foundation/testsuite/src/StringTest.cpp index 976ec484ed..f64298d6fb 100644 --- a/Foundation/testsuite/src/StringTest.cpp +++ b/Foundation/testsuite/src/StringTest.cpp @@ -812,6 +812,7 @@ void StringTest::testNumericStringPadding() { std::string str; assertTrue (floatToStr(str, 0.999f, 2, 4) == "1.00"); + assertTrue (floatToStr(str, 0.999f, 2, 4, '.', ',') == "1,00"); assertTrue (floatToStr(str, 0.945f, 2, 4) == "0.95"); assertTrue (floatToStr(str, 0.944f, 2, 4) == "0.94"); assertTrue (floatToStr(str, 12.45f, 2, 5) == "12.45"); @@ -829,6 +830,7 @@ void StringTest::testNumericStringPadding() assertTrue (doubleToStr(str, 12.45, 2, 6) == " 12.45"); assertTrue (doubleToStr(str, 12.455, 3, 7) == " 12.455"); assertTrue (doubleToStr(str, 12.455, 2, 6) == " 12.46"); + assertTrue (doubleToStr(str, 12345.678, 3, 6, '.', ',') == "12.345,678"); assertTrue (doubleToStr(str, 1.23556E-16, 2, 6) == "1.24e-16"); }