diff --git a/src/pugixml.cpp b/src/pugixml.cpp index b39aad0..3f4476f 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -3813,9 +3813,21 @@ PUGI__NS_BEGIN return (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) ? 16 : 10; } - PUGI__FN int get_value_int(const char_t* value, int def) + PUGI__FN int get_value_int(const char_t* value, int def, bool* def_set) { - if (!value) return def; + if (!value) + { + if(def_set) + { + *def_set = true; + } + return def; + } + + if(def_set) + { + *def_set = false; + } int base = get_integer_base(value); @@ -3826,9 +3838,21 @@ PUGI__NS_BEGIN #endif } - PUGI__FN unsigned int get_value_uint(const char_t* value, unsigned int def) + PUGI__FN unsigned int get_value_uint(const char_t* value, unsigned int def, bool* def_set) { - if (!value) return def; + if (!value) + { + if(def_set) + { + *def_set = true; + } + return def; + } + + if(def_set) + { + *def_set = false; + } int base = get_integer_base(value); @@ -3839,9 +3863,21 @@ PUGI__NS_BEGIN #endif } - PUGI__FN double get_value_double(const char_t* value, double def) + PUGI__FN double get_value_double(const char_t* value, double def, bool* def_set) { - if (!value) return def; + if (!value) + { + if(def_set) + { + *def_set = true; + } + return def; + } + + if(def_set) + { + *def_set = false; + } #ifdef PUGIXML_WCHAR_MODE return wcstod(value, 0); @@ -3850,9 +3886,21 @@ PUGI__NS_BEGIN #endif } - PUGI__FN float get_value_float(const char_t* value, float def) + PUGI__FN float get_value_float(const char_t* value, float def, bool* def_set) { - if (!value) return def; + if (!value) + { + if(def_set) + { + *def_set = true; + } + return def; + } + + if(def_set) + { + *def_set = false; + } #ifdef PUGIXML_WCHAR_MODE return static_cast(wcstod(value, 0)); @@ -3861,9 +3909,21 @@ PUGI__NS_BEGIN #endif } - PUGI__FN bool get_value_bool(const char_t* value, bool def) + PUGI__FN bool get_value_bool(const char_t* value, bool def, bool* def_set) { - if (!value) return def; + if (!value) + { + if(def_set) + { + *def_set = true; + } + return def; + } + + if(def_set) + { + *def_set = false; + } // only look at first char char_t first = *value; @@ -3873,9 +3933,21 @@ PUGI__NS_BEGIN } #ifdef PUGIXML_HAS_LONG_LONG - PUGI__FN long long get_value_llong(const char_t* value, long long def) + PUGI__FN long long get_value_llong(const char_t* value, long long def, bool* def_set) { - if (!value) return def; + if (!value) + { + if(def_set) + { + *def_set = true; + } + return def; + } + + if(def_set) + { + *def_set = false; + } int base = get_integer_base(value); @@ -3894,9 +3966,21 @@ PUGI__NS_BEGIN #endif } - PUGI__FN unsigned long long get_value_ullong(const char_t* value, unsigned long long def) + PUGI__FN unsigned long long get_value_ullong(const char_t* value, unsigned long long def, bool* def_set) { - if (!value) return def; + if (!value) + { + if(def_set) + { + *def_set = true; + } + return def; + } + + if(def_set) + { + *def_set = false; + } int base = get_integer_base(value); @@ -4452,38 +4536,38 @@ namespace pugi PUGI__FN int xml_attribute::as_int(int def) const { - return impl::get_value_int(_attr ? _attr->value : 0, def); + return impl::get_value_int(_attr ? _attr->value : 0, def, NULL); } PUGI__FN unsigned int xml_attribute::as_uint(unsigned int def) const { - return impl::get_value_uint(_attr ? _attr->value : 0, def); + return impl::get_value_uint(_attr ? _attr->value : 0, def, NULL); } PUGI__FN double xml_attribute::as_double(double def) const { - return impl::get_value_double(_attr ? _attr->value : 0, def); + return impl::get_value_double(_attr ? _attr->value : 0, def, NULL); } PUGI__FN float xml_attribute::as_float(float def) const { - return impl::get_value_float(_attr ? _attr->value : 0, def); + return impl::get_value_float(_attr ? _attr->value : 0, def, NULL); } PUGI__FN bool xml_attribute::as_bool(bool def) const { - return impl::get_value_bool(_attr ? _attr->value : 0, def); + return impl::get_value_bool(_attr ? _attr->value : 0, def, NULL); } #ifdef PUGIXML_HAS_LONG_LONG PUGI__FN long long xml_attribute::as_llong(long long def) const { - return impl::get_value_llong(_attr ? _attr->value : 0, def); + return impl::get_value_llong(_attr ? _attr->value : 0, def, NULL); } PUGI__FN unsigned long long xml_attribute::as_ullong(unsigned long long def) const { - return impl::get_value_ullong(_attr ? _attr->value : 0, def); + return impl::get_value_ullong(_attr ? _attr->value : 0, def, NULL); } #endif @@ -5499,61 +5583,75 @@ namespace pugi return (d && d->value) ? d->value : PUGIXML_TEXT(""); } - PUGI__FN const char_t* xml_text::as_string(const char_t* def) const + PUGI__FN const char_t* xml_text::as_string(const char_t* def, bool* def_set) const { xml_node_struct* d = _data(); - return (d && d->value) ? d->value : def; + if(d && d->value) + { + if(def_set) + { + *def_set = false; + } + return d->value; + } + + if(def_set) + { + *def_set = true; + } + + return def; } - PUGI__FN int xml_text::as_int(int def) const + PUGI__FN int xml_text::as_int(int def, bool* def_set) const { xml_node_struct* d = _data(); - return impl::get_value_int(d ? d->value : 0, def); + return impl::get_value_int(d ? d->value : 0, def, def_set); } - PUGI__FN unsigned int xml_text::as_uint(unsigned int def) const + PUGI__FN unsigned int xml_text::as_uint(unsigned int def, bool* def_set) const { xml_node_struct* d = _data(); - return impl::get_value_uint(d ? d->value : 0, def); + return impl::get_value_uint(d ? d->value : 0, def, def_set); } - PUGI__FN double xml_text::as_double(double def) const + PUGI__FN double xml_text::as_double(double def, bool* def_set) const { xml_node_struct* d = _data(); - return impl::get_value_double(d ? d->value : 0, def); + return impl::get_value_double(d ? d->value : 0, def, def_set); } - PUGI__FN float xml_text::as_float(float def) const + PUGI__FN float xml_text::as_float(float def, bool* def_set) const { xml_node_struct* d = _data(); - return impl::get_value_float(d ? d->value : 0, def); + return impl::get_value_float(d ? d->value : 0, def, def_set); } - PUGI__FN bool xml_text::as_bool(bool def) const + PUGI__FN bool xml_text::as_bool(bool def, bool* def_set) const { xml_node_struct* d = _data(); - return impl::get_value_bool(d ? d->value : 0, def); + return impl::get_value_bool(d ? d->value : 0, def, def_set); } #ifdef PUGIXML_HAS_LONG_LONG - PUGI__FN long long xml_text::as_llong(long long def) const + PUGI__FN long long xml_text::as_llong(long long def, bool* def_set) const { xml_node_struct* d = _data(); - return impl::get_value_llong(d ? d->value : 0, def); + return impl::get_value_llong(d ? d->value : 0, def, def_set); } - PUGI__FN unsigned long long xml_text::as_ullong(unsigned long long def) const + PUGI__FN unsigned long long xml_text::as_ullong(unsigned long long def, bool* def_set) const { xml_node_struct* d = _data(); - return impl::get_value_ullong(d ? d->value : 0, def); + return impl::get_value_ullong(d ? d->value : 0, def, def_set); } #endif diff --git a/src/pugixml.hpp b/src/pugixml.hpp index e252e16..4807881 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -671,21 +671,21 @@ namespace pugi const char_t* get() const; // Get text, or the default value if object is empty - const char_t* as_string(const char_t* def = PUGIXML_TEXT("")) const; + const char_t* as_string(const char_t* def = PUGIXML_TEXT(""), bool* def_set = NULL) const; // Get text as a number, or the default value if conversion did not succeed or object is empty - int as_int(int def = 0) const; - unsigned int as_uint(unsigned int def = 0) const; - double as_double(double def = 0) const; - float as_float(float def = 0) const; + int as_int(int def = 0, bool* def_set = NULL) const; + unsigned int as_uint(unsigned int def = 0, bool* def_set = NULL) const; + double as_double(double def = 0, bool* def_set = NULL) const; + float as_float(float def = 0, bool* def_set = NULL) const; #ifdef PUGIXML_HAS_LONG_LONG - long long as_llong(long long def = 0) const; - unsigned long long as_ullong(unsigned long long def = 0) const; + long long as_llong(long long def = 0, bool* def_set = NULL) const; + unsigned long long as_ullong(unsigned long long def = 0, bool* def_set = NULL) const; #endif // Get text as bool (returns true if first character is in '1tTyY' set), or the default value if object is empty - bool as_bool(bool def = false) const; + bool as_bool(bool def = false, bool* def_set = NULL) const; // Set text (returns false if object is empty or there is not enough memory) bool set(const char_t* rhs);