From 532a81f5cb43813163d85ef251c23a211d00d5c6 Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 22 Apr 2017 18:16:27 +0200 Subject: [PATCH] Changed: Don't use CSString --HG-- branch : develop --- code/nel/src/misc/i_xml.cpp | 48 ++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/code/nel/src/misc/i_xml.cpp b/code/nel/src/misc/i_xml.cpp index 5615d81d5..ae5c8615e 100644 --- a/code/nel/src/misc/i_xml.cpp +++ b/code/nel/src/misc/i_xml.cpp @@ -17,7 +17,6 @@ #include "stdmisc.h" #include "nel/misc/i_xml.h" -#include "nel/misc/sstring.h" #ifndef NL_DONT_USE_EXTERNAL_CODE @@ -1067,6 +1066,7 @@ bool CIXml::getPropertyString (std::string &result, xmlNodePtr node, const std:: // Found return true; } + return false; } @@ -1074,18 +1074,21 @@ bool CIXml::getPropertyString (std::string &result, xmlNodePtr node, const std:: int CIXml::getIntProperty(xmlNodePtr node, const std::string &property, int defaultValue) { - CSString s; - bool b; + std::string s; - b=getPropertyString(s,node,property); - if (b==false) + bool b = getPropertyString(s, node, property); + + if (!b) return defaultValue; - s=s.strip(); - sint val=s.atoi(); - if (val==0 && s!="0") + // remove leading and trailing spaces + s = trim(s); + + sint val; + + if (!fromString(s, val) || (val == 0 && s != "0")) { - nlwarning("bad integer value: %s",s.c_str()); + nlwarning("Bad integer value: %s",s.c_str()); return defaultValue; } @@ -1096,14 +1099,25 @@ int CIXml::getIntProperty(xmlNodePtr node, const std::string &property, int defa double CIXml::getFloatProperty(xmlNodePtr node, const std::string &property, float defaultValue) { - CSString s; - bool b; + std::string s; - b=getPropertyString(s,node,property); - if (b==false) + bool b = getPropertyString(s, node, property); + + if (!b) return defaultValue; - return s.strip().atof(); + // remove leading and trailing spaces + s = trim(s); + + float val; + + if (!fromString(s, val)) + { + nlwarning("Bad float value: %s", s.c_str()); + return defaultValue; + } + + return val; } // *************************************************************************** @@ -1111,10 +1125,10 @@ double CIXml::getFloatProperty(xmlNodePtr node, const std::string &property, flo std::string CIXml::getStringProperty(xmlNodePtr node, const std::string &property, const std::string& defaultValue) { std::string s; - bool b; - b=getPropertyString(s,node,property); - if (b==false) + bool b = getPropertyString(s, node, property); + + if (!b) return defaultValue; return s;