diff options
author | arseny.kapoulkine@gmail.com <arseny.kapoulkine@gmail.com@99668b35-9821-0410-8761-19e4c4f06640> | 2012-03-23 03:08:38 +0000 |
---|---|---|
committer | arseny.kapoulkine@gmail.com <arseny.kapoulkine@gmail.com@99668b35-9821-0410-8761-19e4c4f06640> | 2012-03-23 03:08:38 +0000 |
commit | 48391dbe8c52af5deae62ece3175f0e73da741de (patch) | |
tree | 8b381801e4cb7aec0f594aa93c9b3f3182b34d90 | |
parent | 096a6d0e9c55cf8da165cc64ee4cf06a2f4675c5 (diff) |
Moved default value selection logic into get_value functions, added xml_node::text() accessor
git-svn-id: http://pugixml.googlecode.com/svn/trunk@873 99668b35-9821-0410-8761-19e4c4f06640
-rw-r--r-- | src/pugixml.cpp | 60 | ||||
-rw-r--r-- | src/pugixml.hpp | 8 |
2 files changed, 37 insertions, 31 deletions
diff --git a/src/pugixml.cpp b/src/pugixml.cpp index f332254..28be942 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -3322,6 +3322,8 @@ PUGI__NS_BEGIN // get value with conversion functions PUGI__FN int get_value_int(const char_t* value) { + if (!value) return 0; + #ifdef PUGIXML_WCHAR_MODE return static_cast<int>(wcstol(value, 0, 10)); #else @@ -3331,6 +3333,8 @@ PUGI__NS_BEGIN PUGI__FN unsigned int get_value_uint(const char_t* value) { + if (!value) return 0; + #ifdef PUGIXML_WCHAR_MODE return static_cast<unsigned int>(wcstoul(value, 0, 10)); #else @@ -3340,6 +3344,8 @@ PUGI__NS_BEGIN PUGI__FN double get_value_double(const char_t* value) { + if (!value) return 0; + #ifdef PUGIXML_WCHAR_MODE return wcstod(value, 0); #else @@ -3349,6 +3355,8 @@ PUGI__NS_BEGIN PUGI__FN float get_value_float(const char_t* value) { + if (!value) return 0; + #ifdef PUGIXML_WCHAR_MODE return static_cast<float>(wcstod(value, 0)); #else @@ -3358,6 +3366,8 @@ PUGI__NS_BEGIN PUGI__FN bool get_value_bool(const char_t* value) { + if (!value) return false; + // only look at first char char_t first = *value; @@ -3785,37 +3795,27 @@ namespace pugi PUGI__FN int xml_attribute::as_int() const { - if (!_attr || !_attr->value) return 0; - - return impl::get_value_int(_attr->value); + return impl::get_value_int(_attr ? _attr->value : 0); } PUGI__FN unsigned int xml_attribute::as_uint() const { - if (!_attr || !_attr->value) return 0; - - return impl::get_value_uint(_attr->value); + return impl::get_value_uint(_attr ? _attr->value : 0); } PUGI__FN double xml_attribute::as_double() const { - if (!_attr || !_attr->value) return 0; - - return impl::get_value_double(_attr->value); + return impl::get_value_double(_attr ? _attr->value : 0); } PUGI__FN float xml_attribute::as_float() const { - if (!_attr || !_attr->value) return 0; - - return impl::get_value_float(_attr->value); + return impl::get_value_float(_attr ? _attr->value : 0); } PUGI__FN bool xml_attribute::as_bool() const { - if (!_attr || !_attr->value) return false; - - return impl::get_value_bool(_attr->value); + return impl::get_value_bool(_attr ? _attr->value : 0); } PUGI__FN bool xml_attribute::empty() const @@ -4090,6 +4090,16 @@ namespace pugi return xml_node(static_cast<impl::xml_document_struct*>(page->allocator)); } + const xml_text xml_node::text() const + { + return xml_text(_root); + } + + xml_text xml_node::text() + { + return xml_text(_root); + } + PUGI__FN const char_t* xml_node::child_value() const { if (!_root) return PUGIXML_TEXT(""); @@ -4768,37 +4778,27 @@ namespace pugi PUGI__FN int xml_text::as_int() const { - const char_t* text = get(); - - return text ? impl::get_value_int(text) : 0; + return impl::get_value_int(get()); } PUGI__FN unsigned int xml_text::as_uint() const { - const char_t* text = get(); - - return text ? impl::get_value_uint(text) : 0; + return impl::get_value_uint(get()); } PUGI__FN double xml_text::as_double() const { - const char_t* text = get(); - - return text ? impl::get_value_double(text) : 0; + return impl::get_value_double(get()); } PUGI__FN float xml_text::as_float() const { - const char_t* text = get(); - - return text ? impl::get_value_float(text) : 0; + return impl::get_value_float(get()); } PUGI__FN bool xml_text::as_bool() const { - const char_t* text = get(); - - return text ? impl::get_value_bool(text) : false; + return impl::get_value_bool(get()); } PUGI__FN bool xml_text::set(const char_t* rhs) diff --git a/src/pugixml.hpp b/src/pugixml.hpp index 23480f6..db858d6 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -196,9 +196,11 @@ namespace pugi class xml_attribute_iterator; class xml_tree_walker; - + class xml_node; + class xml_text; + #ifndef PUGIXML_NO_XPATH class xpath_node; class xpath_node_set; @@ -388,6 +390,10 @@ namespace pugi // Get root of DOM tree this node belongs to xml_node root() const; + // Get text object for the current node + const xml_text text() const; + xml_text text(); + // Get child, attribute or next/previous sibling with the specified name xml_node child(const char_t* name) const; xml_attribute attribute(const char_t* name) const; |