From 61f8c4ef0df9d91fe6a684bb1b1572e0a537f66e Mon Sep 17 00:00:00 2001 From: John Stiles Date: Sun, 5 Mar 2017 00:38:34 -0800 Subject: [PATCH] Quoted strings to String() or Key() are auto-sized by template Same fix as previous commit, to prettywriter --- include/rapidjson/prettywriter.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/include/rapidjson/prettywriter.h b/include/rapidjson/prettywriter.h index b68b687..64301b8 100644 --- a/include/rapidjson/prettywriter.h +++ b/include/rapidjson/prettywriter.h @@ -107,7 +107,8 @@ public: return Base::WriteString(str, length); } - bool String(const Ch* str, SizeType length, bool copy = false) { + template + bool String(const T* str, SizeType length, bool copy = false, RAPIDJSON_ENABLEIF((internal::IsSame))) { RAPIDJSON_ASSERT(str != 0); (void)copy; PrettyPrefix(kStringType); @@ -126,7 +127,8 @@ public: return Base::WriteStartObject(); } - bool Key(const Ch* str, SizeType length, bool copy = false) { return String(str, length, copy); } + template + bool Key(const T* str, SizeType length, bool copy = false, RAPIDJSON_ENABLEIF((internal::IsSame))) { return String(str, length, copy); } #if RAPIDJSON_HAS_STDSTRING bool Key(const std::basic_string& str) { @@ -184,8 +186,16 @@ public: //@{ //! Simpler but slower overload. - bool String(const Ch* str) { return String(str, internal::StrLen(str)); } - bool Key(const Ch* str) { return Key(str, internal::StrLen(str)); } + template + bool String(const T* const& str, RAPIDJSON_ENABLEIF((internal::IsSame))) { return String(str, internal::StrLen(str)); } + template + bool Key(const T* const& str, RAPIDJSON_ENABLEIF((internal::IsSame))) { return Key(str, internal::StrLen(str)); } + + //! The compiler can give us the length of quoted strings for free. + template + bool String(const T (&str)[N], RAPIDJSON_ENABLEIF((internal::IsSame))) { return String(str, N-1); } + template + bool Key(const T (&str)[N], RAPIDJSON_ENABLEIF((internal::IsSame))) { return Key(str, N-1); } //@}