From 3cfd675163c0ac1f013b00aa4c1bd4ceed351d28 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Mon, 2 Feb 2015 09:21:28 +0000 Subject: [PATCH 1/5] Add std::string overload to Writer when RAPIDJSON_HAS_STDSTRING defined. --- include/rapidjson/writer.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/rapidjson/writer.h b/include/rapidjson/writer.h index 02d6680..6cd5aaf 100644 --- a/include/rapidjson/writer.h +++ b/include/rapidjson/writer.h @@ -127,6 +127,12 @@ public: return WriteString(str, length); } +#if RAPIDJSON_HAS_STDSTRING + bool String(const std::basic_string& str) { + return String(str.data(), SizeType(str.size())); + } +#endif + bool StartObject() { Prefix(kObjectType); new (level_stack_.template Push()) Level(false); From 8b1bd5b485ea7681bd05cd061cb1034394746d56 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Mon, 2 Feb 2015 09:28:35 +0000 Subject: [PATCH 2/5] Typo --- example/serialize/serialize.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/serialize/serialize.cpp b/example/serialize/serialize.cpp index 68a54ef..dcfda65 100644 --- a/example/serialize/serialize.cpp +++ b/example/serialize/serialize.cpp @@ -19,7 +19,7 @@ protected: void Serialize(Writer& writer) const { // This base class just write out name-value pairs, without wrapping within an object. writer.String("name"); - writer.String(name_.c_str(), (SizeType)name_.length()); // Suppling length of string is faster. + writer.String(name_.c_str(), (SizeType)name_.length()); // Supplying length of string is faster. writer.String("age"); writer.Uint(age_); From 1a76879c12eaacba054d68114aa8a790b43fc8ac Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Mon, 2 Feb 2015 09:34:48 +0000 Subject: [PATCH 3/5] Include if RAPIDJSON_HAS_STDSTRING set. --- include/rapidjson/writer.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/rapidjson/writer.h b/include/rapidjson/writer.h index 6cd5aaf..44d8b1d 100644 --- a/include/rapidjson/writer.h +++ b/include/rapidjson/writer.h @@ -29,6 +29,10 @@ #include "stringbuffer.h" #include // placement new +#if RAPIDJSON_HAS_STDSTRING +#include +#endif + #ifdef _MSC_VER RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant From 9d4f0296ff46f83792cfdb81e2ad4e0e16074ef0 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Mon, 2 Feb 2015 09:35:41 +0000 Subject: [PATCH 4/5] Example uses std::string Writer overload if RAPIDJSON_HAS_STDSTRING set. --- example/serialize/serialize.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/example/serialize/serialize.cpp b/example/serialize/serialize.cpp index dcfda65..4f9278b 100644 --- a/example/serialize/serialize.cpp +++ b/example/serialize/serialize.cpp @@ -19,8 +19,11 @@ protected: void Serialize(Writer& writer) const { // This base class just write out name-value pairs, without wrapping within an object. writer.String("name"); +#ifdef RAPIDJSON_HAS_STDSTRING + writer.String(name_); +#else writer.String(name_.c_str(), (SizeType)name_.length()); // Supplying length of string is faster. - +#endif writer.String("age"); writer.Uint(age_); } @@ -42,7 +45,11 @@ public: writer.StartObject(); writer.String("school"); +#ifdef RAPIDJSON_HAS_STDSTRING + writer.String(school_); +#else writer.String(school_.c_str(), (SizeType)school_.length()); +#endif writer.String("GPA"); writer.Double(GPA_); From e54136d74cb4e3b6ed6fdd9d618e3516a0220bf5 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Mon, 2 Feb 2015 10:05:31 +0000 Subject: [PATCH 5/5] Add std::string overload to PrettyWriter when RAPIDJSON_HAS_STDSTRING defined. --- include/rapidjson/prettywriter.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/rapidjson/prettywriter.h b/include/rapidjson/prettywriter.h index ca62bb7..9109f6d 100644 --- a/include/rapidjson/prettywriter.h +++ b/include/rapidjson/prettywriter.h @@ -82,6 +82,12 @@ public: return Base::WriteString(str, length); } +#if RAPIDJSON_HAS_STDSTRING + bool String(const std::basic_string& str) { + return String(str.data(), SizeType(str.size())); + } +#endif + bool StartObject() { PrettyPrefix(kObjectType); new (Base::level_stack_.template Push()) typename Base::Level(false);