Core: ScanFloat

This commit is contained in:
Mirek Fidler 2023-10-30 10:23:26 +01:00
parent 12183f73dd
commit cb32981c04
5 changed files with 27 additions and 12 deletions

View file

@ -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) = <?xml version="1.0" encoding="UTF-8" ?>
<app>
<x value="0"/>
</app>
(float)ScanDouble(AsString(x)) = 0
ScanFloat(AsString(x)) = 0
===========
x = 0.23
IsNull(x) = false
@ -39,7 +39,7 @@ StoreAsXML(t) = <?xml version="1.0" encoding="UTF-8" ?>
<app>
<x value="0.23"/>
</app>
(float)ScanDouble(AsString(x)) = 0.23
ScanFloat(AsString(x)) = 0.23
===========
x = 1
IsNull(x) = false
@ -59,7 +59,7 @@ StoreAsXML(t) = <?xml version="1.0" encoding="UTF-8" ?>
<app>
<x value="1"/>
</app>
(float)ScanDouble(AsString(x)) = 1
ScanFloat(AsString(x)) = 1
===========
x = 1.23
IsNull(x) = false
@ -79,7 +79,7 @@ StoreAsXML(t) = <?xml version="1.0" encoding="UTF-8" ?>
<app>
<x value="1.23"/>
</app>
(float)ScanDouble(AsString(x)) = 1.23
ScanFloat(AsString(x)) = 1.23
===========
x = 51.23
IsNull(x) = false
@ -99,7 +99,7 @@ StoreAsXML(t) = <?xml version="1.0" encoding="UTF-8" ?>
<app>
<x value="51.23"/>
</app>
(float)ScanDouble(AsString(x)) = 51.23
ScanFloat(AsString(x)) = 51.23
===========
x =
IsNull(x) = true
@ -119,4 +119,4 @@ StoreAsXML(t) = <?xml version="1.0" encoding="UTF-8" ?>
<app>
<x value=""/>
</app>
(float)ScanDouble(AsString(x)) =
ScanFloat(AsString(x)) =

View file

@ -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);

View file

@ -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);

View file

@ -670,6 +670,19 @@ double ScanDouble(const wchar *ptr)
return ScanDbl<wchar, word>(n, ptr, ',') ? n : Null;
}
float ScanFloat(const char *ptr)
{
double n;
ptr = ScanDbl<char, byte>(n, ptr, ',');
return ptr ? n : Null;
}
float ScanFloat(const wchar *ptr)
{
double n;
return ScanDbl<wchar, word>(n, ptr, ',') ? n : Null;
}
double Atof(const char *s)
{
double n;

View file

@ -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()