From cb32981c04d35f061c0d700dac26e0fe546d36a7 Mon Sep 17 00:00:00 2001 From: Mirek Fidler Date: Mon, 30 Oct 2023 10:23:26 +0100 Subject: [PATCH] Core: ScanFloat --- autotest/Float/Etalon.log | 14 +++++++------- autotest/Float/main.cpp | 6 +++--- uppsrc/Core/Convert.h | 2 ++ uppsrc/Core/CvFlt.cpp | 13 +++++++++++++ uppsrc/Core/XML.cpp | 4 ++-- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/autotest/Float/Etalon.log b/autotest/Float/Etalon.log index de6f1104f..7d4418ad2 100644 --- a/autotest/Float/Etalon.log +++ b/autotest/Float/Etalon.log @@ -1,4 +1,4 @@ -* C:\upp\out\autotest\CLANGx64.Debug.Debug_Full\Float.exe 29.10.2023 20:57:55, user: cxl +* C:\upp\out\autotest\CLANGx64.Debug.Debug_Full\Float.exe 30.10.2023 10:22:39, user: cxl =========== x = 0 @@ -19,7 +19,7 @@ StoreAsXML(t) = -(float)ScanDouble(AsString(x)) = 0 +ScanFloat(AsString(x)) = 0 =========== x = 0.23 IsNull(x) = false @@ -39,7 +39,7 @@ StoreAsXML(t) = -(float)ScanDouble(AsString(x)) = 0.23 +ScanFloat(AsString(x)) = 0.23 =========== x = 1 IsNull(x) = false @@ -59,7 +59,7 @@ StoreAsXML(t) = -(float)ScanDouble(AsString(x)) = 1 +ScanFloat(AsString(x)) = 1 =========== x = 1.23 IsNull(x) = false @@ -79,7 +79,7 @@ StoreAsXML(t) = -(float)ScanDouble(AsString(x)) = 1.23 +ScanFloat(AsString(x)) = 1.23 =========== x = 51.23 IsNull(x) = false @@ -99,7 +99,7 @@ StoreAsXML(t) = -(float)ScanDouble(AsString(x)) = 51.23 +ScanFloat(AsString(x)) = 51.23 =========== x = IsNull(x) = true @@ -119,4 +119,4 @@ StoreAsXML(t) = -(float)ScanDouble(AsString(x)) = +ScanFloat(AsString(x)) = diff --git a/autotest/Float/main.cpp b/autotest/Float/main.cpp index 5fb037b4d..5a7ab9c01 100644 --- a/autotest/Float/main.cpp +++ b/autotest/Float/main.cpp @@ -40,9 +40,9 @@ CONSOLE_APP_MAIN LoadFromXML(w, StoreAsXML(t)); ASSERT(t.x == w.x); - DDUMP((float)ScanDouble(AsString(x))); - ASSERT(x == (float)ScanDouble(AsString(x))); - ASSERT(v == (float)ScanDouble(AsString(x))); + DDUMP(ScanFloat(AsString(x))); + ASSERT(x == ScanFloat(AsString(x))); + ASSERT(v == ScanFloat(AsString(x))); }; Test(0); diff --git a/uppsrc/Core/Convert.h b/uppsrc/Core/Convert.h index 833490e6f..cf0f29f8c 100644 --- a/uppsrc/Core/Convert.h +++ b/uppsrc/Core/Convert.h @@ -26,6 +26,8 @@ double ScanDouble(const char *ptr, const char **endptr); double ScanDouble(const wchar *ptr, const wchar **endptr); double ScanDouble(const char *ptr); double ScanDouble(const wchar *ptr); +float ScanFloat(const char *ptr); +float ScanFloat(const wchar *ptr); double Atof(const char *s); diff --git a/uppsrc/Core/CvFlt.cpp b/uppsrc/Core/CvFlt.cpp index 3fc6c97ca..8443b3159 100644 --- a/uppsrc/Core/CvFlt.cpp +++ b/uppsrc/Core/CvFlt.cpp @@ -670,6 +670,19 @@ double ScanDouble(const wchar *ptr) return ScanDbl(n, ptr, ',') ? n : Null; } +float ScanFloat(const char *ptr) +{ + double n; + ptr = ScanDbl(n, ptr, ','); + return ptr ? n : Null; +} + +float ScanFloat(const wchar *ptr) +{ + double n; + return ScanDbl(n, ptr, ',') ? n : Null; +} + double Atof(const char *s) { double n; diff --git a/uppsrc/Core/XML.cpp b/uppsrc/Core/XML.cpp index a8ad80eda..75bae87a8 100644 --- a/uppsrc/Core/XML.cpp +++ b/uppsrc/Core/XML.cpp @@ -688,9 +688,9 @@ double XmlParser::Double(const char *id, double def) const float XmlParser::Float(const char *id, float def) const { - if(id == attr1) return (float)ScanDouble(attrval1); + if(id == attr1) return ScanFloat(attrval1); int q = attr.Find(id); - return q < 0 ? def : (float)ScanDouble(attr[q]); + return q < 0 ? def : ScanFloat(attr[q]); } bool XmlParser::IsText()