From 60add2c64dad09465d0444091fc9c870641bddce Mon Sep 17 00:00:00 2001 From: cxl Date: Thu, 26 Jan 2017 08:24:21 +0000 Subject: [PATCH] Core: Atof (comma safe atof) git-svn-id: svn://ultimatepp.org/upp/trunk@10764 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Convert.cpp | 5 +++++ uppsrc/Core/Convert.h | 2 ++ uppsrc/Core/Core.h | 3 +++ uppsrc/CtrlCore/ParseRTF.cpp | 2 +- uppsrc/Painter/SvgUtil.cpp | 4 ++-- uppsrc/PostgreSQL/PostgreSQL.cpp | 2 +- 6 files changed, 14 insertions(+), 4 deletions(-) diff --git a/uppsrc/Core/Convert.cpp b/uppsrc/Core/Convert.cpp index e985ab4a9..b589130d5 100644 --- a/uppsrc/Core/Convert.cpp +++ b/uppsrc/Core/Convert.cpp @@ -182,6 +182,11 @@ double ScanDouble(const wchar *p, const wchar **endptr, bool accept_comma) return ScanDoubleT(p, endptr, accept_comma); } +double Atof(const char *s) +{ + return Nvl(ScanDouble(s)); +} + Value StrIntValue(const char *s) { if(s && *s) { diff --git a/uppsrc/Core/Convert.h b/uppsrc/Core/Convert.h index 00c42ea89..1bc9f07b9 100644 --- a/uppsrc/Core/Convert.h +++ b/uppsrc/Core/Convert.h @@ -13,6 +13,8 @@ int64 ScanInt64(const char *ptr, const char **endptr = NULL, int radix = double ScanDouble(const char *ptr, const char **endptr = NULL, bool accept_comma = true); double ScanDouble(const wchar *ptr, const wchar **endptr = NULL, bool accept_comma = true); +double Atof(const char *s); + Value StrIntValue(const char *s); inline int StrInt(const char* s) { return ScanInt(s); } diff --git a/uppsrc/Core/Core.h b/uppsrc/Core/Core.h index 2c1492775..fcde4d483 100644 --- a/uppsrc/Core/Core.h +++ b/uppsrc/Core/Core.h @@ -240,6 +240,9 @@ namespace std { #define END_UPP_NAMESPACE } #define UPP Upp +// #define atof @ // atof is broken, as it depends on setlocale - might want ',' instead of '.' breaking a lot of code +// Use Atof instead (which accepts both '.' and ',' as decimal separator) + namespace Upp { #ifndef flagNODEPRECATED diff --git a/uppsrc/CtrlCore/ParseRTF.cpp b/uppsrc/CtrlCore/ParseRTF.cpp index 08f052c73..c4208bcd6 100644 --- a/uppsrc/CtrlCore/ParseRTF.cpp +++ b/uppsrc/CtrlCore/ParseRTF.cpp @@ -835,7 +835,7 @@ bool RTFParser::ReadField(const char *p) face = Font::FindFaceNameIndex(symdef[f + 1]); f = symdef.Find("\\s"); if(f >= 0 && f + 1 < symdef.GetCount()) - height = PointDots(fround(2 * atof(symdef[f + 1]))) >> 1; + height = PointDots(fround(2 * Atof(symdef[f + 1]))) >> 1; if(face < 0) #ifdef PLATFORM_WIN32 face = Font::SYMBOL; diff --git a/uppsrc/Painter/SvgUtil.cpp b/uppsrc/Painter/SvgUtil.cpp index 7fc243ac6..763e91ed5 100644 --- a/uppsrc/Painter/SvgUtil.cpp +++ b/uppsrc/Painter/SvgUtil.cpp @@ -212,13 +212,13 @@ Array GetTransformArgs(String str, const char *command) { if ((endpos = str.Find(',', pos)) < 0) break; double &d = args.Add(); - d = atof(str.Mid(pos, endpos-pos)); + d = Atof(str.Mid(pos, endpos-pos)); pos = endpos+1; } if (args.GetCount() < 2) { if ((endpos = str.Find(')', pos)) >= 0) { double &d = args.Add(); - d = atof(str.Mid(pos, endpos-pos)); + d = Atof(str.Mid(pos, endpos-pos)); } } return args; diff --git a/uppsrc/PostgreSQL/PostgreSQL.cpp b/uppsrc/PostgreSQL/PostgreSQL.cpp index 4f665de0a..9b574163c 100644 --- a/uppsrc/PostgreSQL/PostgreSQL.cpp +++ b/uppsrc/PostgreSQL/PostgreSQL.cpp @@ -641,7 +641,7 @@ void PostgreSQLConnection::GetColumn(int i, Ref f) const f.SetValue(atoi(s)); break; case DOUBLE_V: - f.SetValue(atof(s)); + f.SetValue(Atof(s)); break; case BOOL_V: f.SetValue(*s == 't' ? "1" : "0");