summaryrefslogtreecommitdiff
path: root/src/pugixml.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pugixml.cpp')
-rw-r--r--src/pugixml.cpp82
1 files changed, 52 insertions, 30 deletions
diff --git a/src/pugixml.cpp b/src/pugixml.cpp
index f6e5b5c..0476f50 100644
--- a/src/pugixml.cpp
+++ b/src/pugixml.cpp
@@ -3288,9 +3288,9 @@ PUGI__NS_BEGIN
}
// get value with conversion functions
- PUGI__FN int get_value_int(const char_t* value)
+ PUGI__FN int get_value_int(const char_t* value, int def)
{
- if (!value) return 0;
+ if (!value) return def;
#ifdef PUGIXML_WCHAR_MODE
return static_cast<int>(wcstol(value, 0, 10));
@@ -3299,9 +3299,9 @@ PUGI__NS_BEGIN
#endif
}
- PUGI__FN unsigned int get_value_uint(const char_t* value)
+ PUGI__FN unsigned int get_value_uint(const char_t* value, unsigned int def)
{
- if (!value) return 0;
+ if (!value) return def;
#ifdef PUGIXML_WCHAR_MODE
return static_cast<unsigned int>(wcstoul(value, 0, 10));
@@ -3310,9 +3310,9 @@ PUGI__NS_BEGIN
#endif
}
- PUGI__FN double get_value_double(const char_t* value)
+ PUGI__FN double get_value_double(const char_t* value, double def)
{
- if (!value) return 0;
+ if (!value) return def;
#ifdef PUGIXML_WCHAR_MODE
return wcstod(value, 0);
@@ -3321,9 +3321,9 @@ PUGI__NS_BEGIN
#endif
}
- PUGI__FN float get_value_float(const char_t* value)
+ PUGI__FN float get_value_float(const char_t* value, float def)
{
- if (!value) return 0;
+ if (!value) return def;
#ifdef PUGIXML_WCHAR_MODE
return static_cast<float>(wcstod(value, 0));
@@ -3332,9 +3332,9 @@ PUGI__NS_BEGIN
#endif
}
- PUGI__FN bool get_value_bool(const char_t* value)
+ PUGI__FN bool get_value_bool(const char_t* value, bool def)
{
- if (!value) return false;
+ if (!value) return def;
// only look at first char
char_t first = *value;
@@ -3775,29 +3775,34 @@ namespace pugi
return _attr && _attr->prev_attribute_c->next_attribute ? xml_attribute(_attr->prev_attribute_c) : xml_attribute();
}
- PUGI__FN int xml_attribute::as_int() const
+ PUGI__FN const char_t* xml_attribute::as_string(const char_t* def) const
{
- return impl::get_value_int(_attr ? _attr->value : 0);
+ return (_attr && _attr->value) ? _attr->value : def;
}
- PUGI__FN unsigned int xml_attribute::as_uint() const
+ PUGI__FN int xml_attribute::as_int(int def) const
{
- return impl::get_value_uint(_attr ? _attr->value : 0);
+ return impl::get_value_int(_attr ? _attr->value : 0, def);
}
- PUGI__FN double xml_attribute::as_double() const
+ PUGI__FN unsigned int xml_attribute::as_uint(unsigned int def) const
{
- return impl::get_value_double(_attr ? _attr->value : 0);
+ return impl::get_value_uint(_attr ? _attr->value : 0, def);
}
- PUGI__FN float xml_attribute::as_float() const
+ PUGI__FN double xml_attribute::as_double(double def) const
{
- return impl::get_value_float(_attr ? _attr->value : 0);
+ return impl::get_value_double(_attr ? _attr->value : 0, def);
}
- PUGI__FN bool xml_attribute::as_bool() const
+ PUGI__FN float xml_attribute::as_float(float def) const
{
- return impl::get_value_bool(_attr ? _attr->value : 0);
+ return impl::get_value_float(_attr ? _attr->value : 0, def);
+ }
+
+ PUGI__FN bool xml_attribute::as_bool(bool def) const
+ {
+ return impl::get_value_bool(_attr ? _attr->value : 0, def);
}
PUGI__FN bool xml_attribute::empty() const
@@ -4768,29 +4773,46 @@ namespace pugi
return (d && d->value) ? d->value : PUGIXML_TEXT("");
}
- PUGI__FN int xml_text::as_int() const
+ PUGI__FN const char_t* xml_text::as_string(const char_t* def) const
{
- return impl::get_value_int(get());
+ xml_node_struct* d = _data();
+
+ return (d && d->value) ? d->value : def;
+ }
+
+ PUGI__FN int xml_text::as_int(int def) const
+ {
+ xml_node_struct* d = _data();
+
+ return impl::get_value_int(d ? d->value : 0, def);
}
- PUGI__FN unsigned int xml_text::as_uint() const
+ PUGI__FN unsigned int xml_text::as_uint(unsigned int def) const
{
- return impl::get_value_uint(get());
+ xml_node_struct* d = _data();
+
+ return impl::get_value_uint(d ? d->value : 0, def);
}
- PUGI__FN double xml_text::as_double() const
+ PUGI__FN double xml_text::as_double(double def) const
{
- return impl::get_value_double(get());
+ xml_node_struct* d = _data();
+
+ return impl::get_value_double(d ? d->value : 0, def);
}
- PUGI__FN float xml_text::as_float() const
+ PUGI__FN float xml_text::as_float(float def) const
{
- return impl::get_value_float(get());
+ xml_node_struct* d = _data();
+
+ return impl::get_value_float(d ? d->value : 0, def);
}
- PUGI__FN bool xml_text::as_bool() const
+ PUGI__FN bool xml_text::as_bool(bool def) const
{
- return impl::get_value_bool(get());
+ xml_node_struct* d = _data();
+
+ return impl::get_value_bool(d ? d->value : 0, def);
}
PUGI__FN bool xml_text::set(const char_t* rhs)