diff --git a/example/serialize/serialize.cpp b/example/serialize/serialize.cpp index 68a54ef..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"); - writer.String(name_.c_str(), (SizeType)name_.length()); // Suppling length of string is faster. - +#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_); 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); diff --git a/include/rapidjson/writer.h b/include/rapidjson/writer.h index 02d6680..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 @@ -127,6 +131,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);