From 32f0a8bd3a5c9f3c454164f4d23289851b0de3e7 Mon Sep 17 00:00:00 2001 From: Steve Doiel Date: Tue, 6 Jan 2015 15:33:56 -0800 Subject: Add xml_text::set for float Make float/double round-trip --- src/pugixml.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/pugixml.cpp') diff --git a/src/pugixml.cpp b/src/pugixml.cpp index dd3f427..6608d8d 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -3954,10 +3954,18 @@ PUGI__NS_BEGIN return set_value_buffer(dest, header, header_mask, buf); } + PUGI__FN bool set_value_convert(char_t*& dest, uintptr_t& header, uintptr_t header_mask, float value) + { + char buf[128]; + sprintf(buf, "%.9g", value); + + return set_value_buffer(dest, header, header_mask, buf); + } + PUGI__FN bool set_value_convert(char_t*& dest, uintptr_t& header, uintptr_t header_mask, double value) { char buf[128]; - sprintf(buf, "%g", value); + sprintf(buf, "%.17g", value); return set_value_buffer(dest, header, header_mask, buf); } @@ -5603,6 +5611,13 @@ namespace pugi return dn ? impl::set_value_convert(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs) : false; } + PUGI__FN bool xml_text::set(float rhs) + { + xml_node_struct* dn = _data_new(); + + return dn ? impl::set_value_convert(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs) : false; + } + PUGI__FN bool xml_text::set(double rhs) { xml_node_struct* dn = _data_new(); -- cgit v1.2.3 From 4ae1940065c415223445efb23d3200d1b0b1d4a1 Mon Sep 17 00:00:00 2001 From: Steve Doiel Date: Fri, 16 Jan 2015 14:55:10 -0800 Subject: Fix attribute round trip for float as well --- src/pugixml.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/pugixml.cpp') diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 6608d8d..2ed94f3 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -4608,6 +4608,13 @@ namespace pugi return impl::set_value_convert(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs); } + PUGI__FN bool xml_attribute::set_value(float rhs) + { + if (!_attr) return false; + + return impl::set_value_convert(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs); + } + PUGI__FN bool xml_attribute::set_value(bool rhs) { if (!_attr) return false; -- cgit v1.2.3 From 53525a037b45ecf4dc29bf6700ad384647541da2 Mon Sep 17 00:00:00 2001 From: Steve Doiel Date: Fri, 16 Jan 2015 15:20:28 -0800 Subject: Add a couple of more overloads for floats --- src/pugixml.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/pugixml.cpp') diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 2ed94f3..9760e9f 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -4553,6 +4553,12 @@ namespace pugi return *this; } + PUGI__FN xml_attribute& xml_attribute::operator=(float rhs) + { + set_value(rhs); + return *this; + } + PUGI__FN xml_attribute& xml_attribute::operator=(bool rhs) { set_value(rhs); @@ -5679,6 +5685,12 @@ namespace pugi return *this; } + PUGI__FN xml_text& xml_text::operator=(float rhs) + { + set(rhs); + return *this; + } + PUGI__FN xml_text& xml_text::operator=(bool rhs) { set(rhs); -- cgit v1.2.3