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
This commit is contained in:
parent
096a6d0e9c
commit
48391dbe8c
@ -3322,6 +3322,8 @@ PUGI__NS_BEGIN
|
|||||||
// get value with conversion functions
|
// 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)
|
||||||
{
|
{
|
||||||
|
if (!value) return 0;
|
||||||
|
|
||||||
#ifdef PUGIXML_WCHAR_MODE
|
#ifdef PUGIXML_WCHAR_MODE
|
||||||
return static_cast<int>(wcstol(value, 0, 10));
|
return static_cast<int>(wcstol(value, 0, 10));
|
||||||
#else
|
#else
|
||||||
@ -3331,6 +3333,8 @@ PUGI__NS_BEGIN
|
|||||||
|
|
||||||
PUGI__FN unsigned int get_value_uint(const char_t* value)
|
PUGI__FN unsigned int get_value_uint(const char_t* value)
|
||||||
{
|
{
|
||||||
|
if (!value) return 0;
|
||||||
|
|
||||||
#ifdef PUGIXML_WCHAR_MODE
|
#ifdef PUGIXML_WCHAR_MODE
|
||||||
return static_cast<unsigned int>(wcstoul(value, 0, 10));
|
return static_cast<unsigned int>(wcstoul(value, 0, 10));
|
||||||
#else
|
#else
|
||||||
@ -3340,6 +3344,8 @@ PUGI__NS_BEGIN
|
|||||||
|
|
||||||
PUGI__FN double get_value_double(const char_t* value)
|
PUGI__FN double get_value_double(const char_t* value)
|
||||||
{
|
{
|
||||||
|
if (!value) return 0;
|
||||||
|
|
||||||
#ifdef PUGIXML_WCHAR_MODE
|
#ifdef PUGIXML_WCHAR_MODE
|
||||||
return wcstod(value, 0);
|
return wcstod(value, 0);
|
||||||
#else
|
#else
|
||||||
@ -3349,6 +3355,8 @@ PUGI__NS_BEGIN
|
|||||||
|
|
||||||
PUGI__FN float get_value_float(const char_t* value)
|
PUGI__FN float get_value_float(const char_t* value)
|
||||||
{
|
{
|
||||||
|
if (!value) return 0;
|
||||||
|
|
||||||
#ifdef PUGIXML_WCHAR_MODE
|
#ifdef PUGIXML_WCHAR_MODE
|
||||||
return static_cast<float>(wcstod(value, 0));
|
return static_cast<float>(wcstod(value, 0));
|
||||||
#else
|
#else
|
||||||
@ -3358,6 +3366,8 @@ PUGI__NS_BEGIN
|
|||||||
|
|
||||||
PUGI__FN bool get_value_bool(const char_t* value)
|
PUGI__FN bool get_value_bool(const char_t* value)
|
||||||
{
|
{
|
||||||
|
if (!value) return false;
|
||||||
|
|
||||||
// only look at first char
|
// only look at first char
|
||||||
char_t first = *value;
|
char_t first = *value;
|
||||||
|
|
||||||
@ -3785,37 +3795,27 @@ namespace pugi
|
|||||||
|
|
||||||
PUGI__FN int xml_attribute::as_int() const
|
PUGI__FN int xml_attribute::as_int() const
|
||||||
{
|
{
|
||||||
if (!_attr || !_attr->value) return 0;
|
return impl::get_value_int(_attr ? _attr->value : 0);
|
||||||
|
|
||||||
return impl::get_value_int(_attr->value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PUGI__FN unsigned int xml_attribute::as_uint() const
|
PUGI__FN unsigned int xml_attribute::as_uint() const
|
||||||
{
|
{
|
||||||
if (!_attr || !_attr->value) return 0;
|
return impl::get_value_uint(_attr ? _attr->value : 0);
|
||||||
|
|
||||||
return impl::get_value_uint(_attr->value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PUGI__FN double xml_attribute::as_double() const
|
PUGI__FN double xml_attribute::as_double() const
|
||||||
{
|
{
|
||||||
if (!_attr || !_attr->value) return 0;
|
return impl::get_value_double(_attr ? _attr->value : 0);
|
||||||
|
|
||||||
return impl::get_value_double(_attr->value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PUGI__FN float xml_attribute::as_float() const
|
PUGI__FN float xml_attribute::as_float() const
|
||||||
{
|
{
|
||||||
if (!_attr || !_attr->value) return 0;
|
return impl::get_value_float(_attr ? _attr->value : 0);
|
||||||
|
|
||||||
return impl::get_value_float(_attr->value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PUGI__FN bool xml_attribute::as_bool() const
|
PUGI__FN bool xml_attribute::as_bool() const
|
||||||
{
|
{
|
||||||
if (!_attr || !_attr->value) return false;
|
return impl::get_value_bool(_attr ? _attr->value : 0);
|
||||||
|
|
||||||
return impl::get_value_bool(_attr->value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PUGI__FN bool xml_attribute::empty() const
|
PUGI__FN bool xml_attribute::empty() const
|
||||||
@ -4090,6 +4090,16 @@ namespace pugi
|
|||||||
return xml_node(static_cast<impl::xml_document_struct*>(page->allocator));
|
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
|
PUGI__FN const char_t* xml_node::child_value() const
|
||||||
{
|
{
|
||||||
if (!_root) return PUGIXML_TEXT("");
|
if (!_root) return PUGIXML_TEXT("");
|
||||||
@ -4768,37 +4778,27 @@ namespace pugi
|
|||||||
|
|
||||||
PUGI__FN int xml_text::as_int() const
|
PUGI__FN int xml_text::as_int() const
|
||||||
{
|
{
|
||||||
const char_t* text = get();
|
return impl::get_value_int(get());
|
||||||
|
|
||||||
return text ? impl::get_value_int(text) : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PUGI__FN unsigned int xml_text::as_uint() const
|
PUGI__FN unsigned int xml_text::as_uint() const
|
||||||
{
|
{
|
||||||
const char_t* text = get();
|
return impl::get_value_uint(get());
|
||||||
|
|
||||||
return text ? impl::get_value_uint(text) : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PUGI__FN double xml_text::as_double() const
|
PUGI__FN double xml_text::as_double() const
|
||||||
{
|
{
|
||||||
const char_t* text = get();
|
return impl::get_value_double(get());
|
||||||
|
|
||||||
return text ? impl::get_value_double(text) : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PUGI__FN float xml_text::as_float() const
|
PUGI__FN float xml_text::as_float() const
|
||||||
{
|
{
|
||||||
const char_t* text = get();
|
return impl::get_value_float(get());
|
||||||
|
|
||||||
return text ? impl::get_value_float(text) : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PUGI__FN bool xml_text::as_bool() const
|
PUGI__FN bool xml_text::as_bool() const
|
||||||
{
|
{
|
||||||
const char_t* text = get();
|
return impl::get_value_bool(get());
|
||||||
|
|
||||||
return text ? impl::get_value_bool(text) : false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PUGI__FN bool xml_text::set(const char_t* rhs)
|
PUGI__FN bool xml_text::set(const char_t* rhs)
|
||||||
|
|||||||
@ -199,6 +199,8 @@ namespace pugi
|
|||||||
|
|
||||||
class xml_node;
|
class xml_node;
|
||||||
|
|
||||||
|
class xml_text;
|
||||||
|
|
||||||
#ifndef PUGIXML_NO_XPATH
|
#ifndef PUGIXML_NO_XPATH
|
||||||
class xpath_node;
|
class xpath_node;
|
||||||
class xpath_node_set;
|
class xpath_node_set;
|
||||||
@ -388,6 +390,10 @@ namespace pugi
|
|||||||
// Get root of DOM tree this node belongs to
|
// Get root of DOM tree this node belongs to
|
||||||
xml_node root() const;
|
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
|
// Get child, attribute or next/previous sibling with the specified name
|
||||||
xml_node child(const char_t* name) const;
|
xml_node child(const char_t* name) const;
|
||||||
xml_attribute attribute(const char_t* name) const;
|
xml_attribute attribute(const char_t* name) const;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user