Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
rapidjson
Commits
d5d18cf6
Commit
d5d18cf6
authored
Mar 15, 2017
by
John Stiles
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix template length optimization issue in PrettyWriter
Missed PrettyWriter in the initial fix for Issue #889
parent
f0c108b5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
20 deletions
+18
-20
prettywriter.h
include/rapidjson/prettywriter.h
+4
-20
prettywritertest.cpp
test/unittest/prettywritertest.cpp
+14
-0
No files found.
include/rapidjson/prettywriter.h
View file @
d5d18cf6
...
...
@@ -107,8 +107,7 @@ public:
return
Base
::
WriteString
(
str
,
length
);
}
template
<
typename
T
>
RAPIDJSON_ENABLEIF_RETURN
((
internal
::
IsSame
<
Ch
,
T
>
),
(
bool
))
String
(
const
T
*
str
,
SizeType
length
,
bool
copy
=
false
)
{
bool
String
(
const
Ch
*
str
,
SizeType
length
,
bool
copy
=
false
)
{
RAPIDJSON_ASSERT
(
str
!=
0
);
(
void
)
copy
;
PrettyPrefix
(
kStringType
);
...
...
@@ -127,8 +126,7 @@ public:
return
Base
::
WriteStartObject
();
}
template
<
typename
T
>
RAPIDJSON_ENABLEIF_RETURN
((
internal
::
IsSame
<
Ch
,
T
>
),
(
bool
))
Key
(
const
T
*
str
,
SizeType
length
,
bool
copy
=
false
)
{
return
String
(
str
,
length
,
copy
);
}
bool
Key
(
const
Ch
*
str
,
SizeType
length
,
bool
copy
=
false
)
{
return
String
(
str
,
length
,
copy
);
}
#if RAPIDJSON_HAS_STDSTRING
bool
Key
(
const
std
::
basic_string
<
Ch
>&
str
)
{
...
...
@@ -186,22 +184,8 @@ public:
//@{
//! Simpler but slower overload.
template
<
typename
T
>
RAPIDJSON_ENABLEIF_RETURN
((
internal
::
IsSame
<
Ch
,
T
>
),
(
bool
))
String
(
const
T
*
const
&
str
)
{
return
String
(
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
);
}
bool
String
(
const
Ch
*
str
)
{
return
String
(
str
,
internal
::
StrLen
(
str
));
}
bool
Key
(
const
Ch
*
str
)
{
return
Key
(
str
,
internal
::
StrLen
(
str
));
}
//@}
...
...
test/unittest/prettywritertest.cpp
View file @
d5d18cf6
...
...
@@ -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
static
PrettyWriter
<
StringBuffer
>
WriterGen
(
StringBuffer
&
target
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment