Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
yaml-cpp
Commits
9ee39287
Unverified
Commit
9ee39287
authored
Jul 05, 2021
by
theamarin
Committed by
GitHub
Jul 04, 2021
Browse files
Prevent trailing spaces when emitting literal strings (#1005)
parent
a6bbe0e5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
2 deletions
+16
-2
src/emitterutils.cpp
src/emitterutils.cpp
+2
-2
test/integration/emitter_test.cpp
test/integration/emitter_test.cpp
+14
-0
No files found.
src/emitterutils.cpp
View file @
9ee39287
...
@@ -366,13 +366,13 @@ bool WriteDoubleQuotedString(ostream_wrapper& out, const std::string& str,
...
@@ -366,13 +366,13 @@ bool WriteDoubleQuotedString(ostream_wrapper& out, const std::string& str,
bool
WriteLiteralString
(
ostream_wrapper
&
out
,
const
std
::
string
&
str
,
bool
WriteLiteralString
(
ostream_wrapper
&
out
,
const
std
::
string
&
str
,
std
::
size_t
indent
)
{
std
::
size_t
indent
)
{
out
<<
"|
\n
"
;
out
<<
"|
\n
"
;
out
<<
IndentTo
(
indent
);
int
codePoint
;
int
codePoint
;
for
(
std
::
string
::
const_iterator
i
=
str
.
begin
();
for
(
std
::
string
::
const_iterator
i
=
str
.
begin
();
GetNextCodePointAndAdvance
(
codePoint
,
i
,
str
.
end
());)
{
GetNextCodePointAndAdvance
(
codePoint
,
i
,
str
.
end
());)
{
if
(
codePoint
==
'\n'
)
{
if
(
codePoint
==
'\n'
)
{
out
<<
"
\n
"
<<
IndentTo
(
indent
)
;
out
<<
"
\n
"
;
}
else
{
}
else
{
out
<<
IndentTo
(
indent
);
WriteCodePoint
(
out
,
codePoint
);
WriteCodePoint
(
out
,
codePoint
);
}
}
}
}
...
...
test/integration/emitter_test.cpp
View file @
9ee39287
...
@@ -382,6 +382,20 @@ TEST_F(EmitterTest, ScalarFormat) {
...
@@ -382,6 +382,20 @@ TEST_F(EmitterTest, ScalarFormat) {
"crazy
\t
symbols that we like"
);
"crazy
\t
symbols that we like"
);
}
}
TEST_F
(
EmitterTest
,
LiteralWithoutTrailingSpaces
)
{
out
<<
YAML
::
BeginMap
;
out
<<
YAML
::
Key
<<
"key"
;
out
<<
YAML
::
Value
<<
YAML
::
Literal
;
out
<<
"expect that with two newlines
\n\n
"
"no spaces are emitted in the empty line"
;
out
<<
YAML
::
EndMap
;
ExpectEmit
(
"key: |
\n
"
" expect that with two newlines
\n\n
"
" no spaces are emitted in the empty line"
);
}
TEST_F
(
EmitterTest
,
AutoLongKeyScalar
)
{
TEST_F
(
EmitterTest
,
AutoLongKeyScalar
)
{
out
<<
BeginMap
;
out
<<
BeginMap
;
out
<<
Key
<<
Literal
<<
"multi-line
\n
scalar"
;
out
<<
Key
<<
Literal
<<
"multi-line
\n
scalar"
;
...
...
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