@@ -107,7 +107,8 @@ class PrettyWriter : public Writer<OutputStream, SourceEncoding, TargetEncoding,
107
107
return Base::WriteString (str, length);
108
108
}
109
109
110
- bool String (const Ch* str, SizeType length, bool copy = false ) {
110
+ template <typename T>
111
+ bool String (const T* str, SizeType length, bool copy = false , RAPIDJSON_ENABLEIF((internal::IsSame<Ch, T>))) {
111
112
RAPIDJSON_ASSERT (str != 0 );
112
113
(void )copy;
113
114
PrettyPrefix (kStringType );
@@ -126,7 +127,8 @@ class PrettyWriter : public Writer<OutputStream, SourceEncoding, TargetEncoding,
126
127
return Base::WriteStartObject ();
127
128
}
128
129
129
- bool Key (const Ch* str, SizeType length, bool copy = false ) { return String (str, length, copy); }
130
+ template <typename T>
131
+ bool Key (const T* str, SizeType length, bool copy = false , RAPIDJSON_ENABLEIF((internal::IsSame<Ch, T>))) { return String (str, length, copy); }
130
132
131
133
#if RAPIDJSON_HAS_STDSTRING
132
134
bool Key (const std::basic_string<Ch>& str) {
@@ -184,8 +186,16 @@ class PrettyWriter : public Writer<OutputStream, SourceEncoding, TargetEncoding,
184
186
// @{
185
187
186
188
// ! Simpler but slower overload.
187
- bool String (const Ch* str) { return String (str, internal::StrLen (str)); }
188
- bool Key (const Ch* str) { return Key (str, internal::StrLen (str)); }
189
+ template <typename T>
190
+ bool String (const T* const & str, RAPIDJSON_ENABLEIF((internal::IsSame<Ch, T>))) { return String (str, internal::StrLen (str)); }
191
+ template <typename T>
192
+ bool Key (const T* const & str, RAPIDJSON_ENABLEIF((internal::IsSame<Ch, T>))) { return Key (str, internal::StrLen (str)); }
193
+
194
+ // ! The compiler can give us the length of quoted strings for free.
195
+ template <typename T, size_t N>
196
+ bool String (const T (&str)[N], RAPIDJSON_ENABLEIF((internal::IsSame<Ch, T>))) { return String (str, N-1 ); }
197
+ template <typename T, size_t N>
198
+ bool Key (const T (&str)[N], RAPIDJSON_ENABLEIF((internal::IsSame<Ch, T>))) { return Key (str, N-1 ); }
189
199
190
200
// @}
191
201
0 commit comments