diff options
| author | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2014-01-15 04:28:10 +0000 | 
|---|---|---|
| committer | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2014-01-15 04:28:10 +0000 | 
| commit | 7f6b062e9f51c98e56713b1869c01573d7fe855f (patch) | |
| tree | c372c947728a08361f2a5575d2f50cd9cf80cb08 /src | |
| parent | 783af7926420e17f10d80d74cf3459b2c87d2541 (diff) | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/pugixml.cpp | 27 | 
1 files changed, 22 insertions, 5 deletions
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<int>(wcstol(value, 0, 10)); +		return static_cast<int>(wcstol(value, 0, base));  	#else -		return static_cast<int>(strtol(value, 0, 10)); +		return static_cast<int>(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<unsigned int>(wcstoul(value, 0, 10)); +		return static_cast<unsigned int>(wcstoul(value, 0, base));  	#else -		return static_cast<unsigned int>(strtoul(value, 0, 10)); +		return static_cast<unsigned int>(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)  	{  	}  | 
