From ba1b2017dbc865735bebe01a0f0da2e97f1dab12 Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Thu, 20 May 2010 20:35:49 +0000 Subject: as_* functions now all use strto*/wcsto* functions; this unifies the behavior and fixes large unsigned integer parsing in as_uint git-svn-id: http://pugixml.googlecode.com/svn/trunk@438 99668b35-9821-0410-8761-19e4c4f06640 --- src/pugixml.cpp | 12 +++++------- tests/test_dom_modify.cpp | 6 +++--- tests/test_dom_traverse.cpp | 3 ++- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 04fb1db..e6784ae 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -3067,7 +3067,7 @@ namespace pugi #ifdef PUGIXML_WCHAR_MODE return (int)wcstol(_attr->value, 0, 10); #else - return atoi(_attr->value); + return (int)strtol(_attr->value, 0, 10); #endif } @@ -3076,12 +3076,10 @@ namespace pugi if (!_attr || !_attr->value) return 0; #ifdef PUGIXML_WCHAR_MODE - int result = (int)wcstol(_attr->value, 0, 10); + return (unsigned int)wcstoul(_attr->value, 0, 10); #else - int result = atoi(_attr->value); + return (unsigned int)strtoul(_attr->value, 0, 10); #endif - - return result < 0 ? 0 : static_cast(result); } double xml_attribute::as_double() const @@ -3091,7 +3089,7 @@ namespace pugi #ifdef PUGIXML_WCHAR_MODE return wcstod(_attr->value, 0); #else - return atof(_attr->value); + return strtod(_attr->value, 0); #endif } @@ -3102,7 +3100,7 @@ namespace pugi #ifdef PUGIXML_WCHAR_MODE return (float)wcstod(_attr->value, 0); #else - return (float)atof(_attr->value); + return (float)strtod(_attr->value, 0); #endif } diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index 7d30420..cb4a5ab 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -34,8 +34,8 @@ TEST_XML(dom_attr_set_value, "")); + CHECK_NODE(node, STR("")); } TEST_XML(dom_node_set_name, "text") diff --git a/tests/test_dom_traverse.cpp b/tests/test_dom_traverse.cpp index 7d04bda..366c683 100644 --- a/tests/test_dom_traverse.cpp +++ b/tests/test_dom_traverse.cpp @@ -91,7 +91,7 @@ TEST_XML(dom_attr_as_int, "") +TEST_XML(dom_attr_as_uint, "") { xml_node node = doc.child(STR("node")); @@ -99,6 +99,7 @@ TEST_XML(dom_attr_as_uint, "") CHECK(node.attribute(STR("attr1")).as_uint() == 0); CHECK(node.attribute(STR("attr2")).as_uint() == 1); CHECK(node.attribute(STR("attr3")).as_uint() == 2147483647); + CHECK(node.attribute(STR("attr4")).as_uint() == 4294967295u); } TEST_XML(dom_attr_as_float, "") -- cgit v1.2.3