Commit d5d18cf6 authored by John Stiles's avatar John Stiles

Fix template length optimization issue in PrettyWriter

Missed PrettyWriter in the initial fix for Issue #889
parent f0c108b5
...@@ -107,8 +107,7 @@ public: ...@@ -107,8 +107,7 @@ public:
return Base::WriteString(str, length); return Base::WriteString(str, length);
} }
template <typename T> bool String(const Ch* str, SizeType length, bool copy = false) {
RAPIDJSON_ENABLEIF_RETURN((internal::IsSame<Ch, T>), (bool)) String(const T* str, SizeType length, bool copy = false) {
RAPIDJSON_ASSERT(str != 0); RAPIDJSON_ASSERT(str != 0);
(void)copy; (void)copy;
PrettyPrefix(kStringType); PrettyPrefix(kStringType);
...@@ -127,8 +126,7 @@ public: ...@@ -127,8 +126,7 @@ public:
return Base::WriteStartObject(); return Base::WriteStartObject();
} }
template <typename T> bool Key(const Ch* str, SizeType length, bool copy = false) { return String(str, length, copy); }
RAPIDJSON_ENABLEIF_RETURN((internal::IsSame<Ch, T>), (bool)) Key(const T* str, SizeType length, bool copy = false) { return String(str, length, copy); }
#if RAPIDJSON_HAS_STDSTRING #if RAPIDJSON_HAS_STDSTRING
bool Key(const std::basic_string<Ch>& str) { bool Key(const std::basic_string<Ch>& str) {
...@@ -186,22 +184,8 @@ public: ...@@ -186,22 +184,8 @@ public:
//@{ //@{
//! Simpler but slower overload. //! Simpler but slower overload.
template <typename T> bool String(const Ch* str) { return String(str, internal::StrLen(str)); }
RAPIDJSON_ENABLEIF_RETURN((internal::IsSame<Ch, T>), (bool)) String(const T* const& str) { return String(str, internal::StrLen(str)); } bool Key(const Ch* str) { return Key(str, internal::StrLen(str)); }
template <typename T>
RAPIDJSON_ENABLEIF_RETURN((internal::IsSame<Ch, T>), (bool)) Key(const T* const& str) { return Key(str, internal::StrLen(str)); }
//! The compiler can give us the length of quoted strings for free.
template <typename T, size_t N>
RAPIDJSON_ENABLEIF_RETURN((internal::IsSame<Ch, T>), (bool)) String(const T (&str)[N]) {
RAPIDJSON_ASSERT(str[N-1] == '\0'); // you must pass in a null-terminated string (quoted constant strings are always null-terminated)
return String(str, N-1);
}
template <typename T, size_t N>
RAPIDJSON_ENABLEIF_RETURN((internal::IsSame<Ch, T>), (bool)) Key(const T (&str)[N]) {
RAPIDJSON_ASSERT(str[N-1] == '\0'); // you must pass in a null-terminated string (quoted constant strings are always null-terminated)
return Key(str, N-1);
}
//@} //@}
......
...@@ -258,6 +258,20 @@ TEST(PrettyWriter, InvalidEventSequence) { ...@@ -258,6 +258,20 @@ TEST(PrettyWriter, InvalidEventSequence) {
} }
} }
TEST(PrettyWriter, Issue_889) {
char buf[100] = "Hello";
StringBuffer buffer;
PrettyWriter<StringBuffer> writer(buffer);
writer.StartArray();
writer.String(buf);
writer.EndArray();
EXPECT_STREQ("[\n \"Hello\"\n]", buffer.GetString());
EXPECT_TRUE(writer.IsComplete()); \
}
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
static PrettyWriter<StringBuffer> WriterGen(StringBuffer &target) { static PrettyWriter<StringBuffer> WriterGen(StringBuffer &target) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment