From 7f6b062e9f51c98e56713b1869c01573d7fe855f Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Wed, 15 Jan 2014 04:28:10 +0000 Subject: Implement automatic hexadecimal decoding for xml_attribute::as_int and xml_text::as_int. This is effectively a form of strtol with base 0, but without octal support. git-svn-id: http://pugixml.googlecode.com/svn/trunk@958 99668b35-9821-0410-8761-19e4c4f06640 --- src/pugixml.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'src/pugixml.cpp') diff --git a/src/pugixml.cpp b/src/pugixml.cpp index be8bcea..b637f27 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -3314,14 +3314,29 @@ PUGI__NS_BEGIN } // get value with conversion functions + PUGI__FN int get_integer_base(const char_t* value) + { + const char_t* s = value; + + while (PUGI__IS_CHARTYPE(*s, ct_space)) + s++; + + if (*s == '-') + s++; + + return (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) ? 16 : 10; + } + PUGI__FN int get_value_int(const char_t* value, int def) { if (!value) return def; + int base = get_integer_base(value); + #ifdef PUGIXML_WCHAR_MODE - return static_cast(wcstol(value, 0, 10)); + return static_cast(wcstol(value, 0, base)); #else - return static_cast(strtol(value, 0, 10)); + return static_cast(strtol(value, 0, base)); #endif } @@ -3329,10 +3344,12 @@ PUGI__NS_BEGIN { if (!value) return def; + int base = get_integer_base(value); + #ifdef PUGIXML_WCHAR_MODE - return static_cast(wcstoul(value, 0, 10)); + return static_cast(wcstoul(value, 0, base)); #else - return static_cast(strtoul(value, 0, 10)); + return static_cast(strtoul(value, 0, base)); #endif } @@ -9876,7 +9893,7 @@ namespace pugi return error ? error : "No error"; } - PUGI__FN xpath_variable::xpath_variable() + PUGI__FN xpath_variable::xpath_variable(): _type(xpath_type_none), _next(0) { } -- cgit v1.2.3