diff options
Diffstat (limited to 'src/lib/util/xmlfile.cpp')
-rw-r--r-- | src/lib/util/xmlfile.cpp | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/src/lib/util/xmlfile.cpp b/src/lib/util/xmlfile.cpp index 2a1bedc7c2c..cfa6bbd8ff5 100644 --- a/src/lib/util/xmlfile.cpp +++ b/src/lib/util/xmlfile.cpp @@ -603,6 +603,19 @@ data_node::attribute_node const *data_node::get_attribute(const char *attribute) //------------------------------------------------- +// get_attribute_string_ptr - get a pointer to +// the string value of the specified attribute; +// if not found, return = nullptr +//------------------------------------------------- + +std::string const *data_node::get_attribute_string_ptr(const char *attribute) const +{ + attribute_node const *attr = get_attribute(attribute); + return attr ? &attr->value : nullptr; +} + + +//------------------------------------------------- // get_attribute_string - get the string // value of the specified attribute; if not // found, return = the provided default @@ -623,9 +636,10 @@ const char *data_node::get_attribute_string(const char *attribute, const char *d long long data_node::get_attribute_int(const char *attribute, long long defvalue) const { - char const *const string = get_attribute_string(attribute, nullptr); - if (!string) + attribute_node const *attr = get_attribute(attribute); + if (!attr) return defvalue; + std::string const &string = attr->value; std::istringstream stream; stream.imbue(std::locale::classic()); @@ -666,14 +680,16 @@ long long data_node::get_attribute_int(const char *attribute, long long defvalue data_node::int_format data_node::get_attribute_int_format(const char *attribute) const { - char const *const string = get_attribute_string(attribute, nullptr); - if (!string) + attribute_node const *attr = get_attribute(attribute); + if (!attr) return int_format::DECIMAL; - else if (string[0] == '$') + std::string const &string = attr->value; + + if (string[0] == '$') return int_format::HEX_DOLLAR; else if (string[0] == '0' && string[1] == 'x') return int_format::HEX_C; - if (string[0] == '#') + else if (string[0] == '#') return int_format::DECIMAL_HASH; else return int_format::DECIMAL; @@ -688,11 +704,11 @@ data_node::int_format data_node::get_attribute_int_format(const char *attribute) float data_node::get_attribute_float(const char *attribute, float defvalue) const { - char const *const string = get_attribute_string(attribute, nullptr); - if (!string) + attribute_node const *attr = get_attribute(attribute); + if (!attr) return defvalue; - std::istringstream stream(string); + std::istringstream stream(attr->value); stream.imbue(std::locale::classic()); float result; return (stream >> result) ? result : defvalue; |