aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2014-10-29 19:25:51 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2014-10-29 19:25:51 +0200
commit7275dc4d919b0cb6f8713d0b4a9a2b507051cded (patch)
tree3ffc5b1df9a479bcddb20187ae9fb7152d8bb8b6
parent382f3ebd7ffe0a12e2ad1e0dc14e02f1122ac3df (diff)
Add value_traits specialization for std::string
The default implementation uses istream::operator>> which ignores spaces.
-rw-r--r--tests/parser/driver.cxx12
-rw-r--r--xml/value-traits16
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/parser/driver.cxx b/tests/parser/driver.cxx
index 4e0fbae..c1c6f3d 100644
--- a/tests/parser/driver.cxx
+++ b/tests/parser/driver.cxx
@@ -470,4 +470,16 @@ main ()
assert (v[3] == parser::end_element);
assert (v[4] == parser::end_element);
}
+
+ // Test space extraction into the std::string value.
+ //
+ {
+ istringstream is ("<root a=' a '> b </root>");
+ parser p (is, "test");
+ p.next_expect (parser::start_element, "root");
+ assert (p.attribute<std::string> ("a") == " a ");
+ p.next_expect (parser::characters);
+ assert (p.value<std::string> () == " b ");
+ p.next_expect (parser::end_element);
+ }
}
diff --git a/xml/value-traits b/xml/value-traits
index 3bf10e0..0c79229 100644
--- a/xml/value-traits
+++ b/xml/value-traits
@@ -39,6 +39,22 @@ namespace xml
}
};
+ template <>
+ struct LIBSTUDXML_EXPORT default_value_traits<std::string>
+ {
+ static std::string
+ parse (std::string s, const parser&)
+ {
+ return s;
+ }
+
+ static std::string
+ serialize (const std::string& v, const serializer&)
+ {
+ return v;
+ }
+ };
+
template <typename T>
struct value_traits: default_value_traits<T> {};