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
bacb74e8
Commit
bacb74e8
authored
Aug 04, 2011
by
Jesse Beder
Browse files
Forced a newline after any comments
parent
b1ac3289
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
3 deletions
+49
-3
src/emitter.cpp
src/emitter.cpp
+10
-2
src/emitterutils.cpp
src/emitterutils.cpp
+1
-1
test/emittertests.cpp
test/emittertests.cpp
+38
-0
No files found.
src/emitter.cpp
View file @
bacb74e8
...
@@ -186,6 +186,7 @@ namespace YAML
...
@@ -186,6 +186,7 @@ namespace YAML
case
ES_WRITING_FLOW_SEQ_ENTRY
:
case
ES_WRITING_FLOW_SEQ_ENTRY
:
return
true
;
return
true
;
case
ES_DONE_WITH_FLOW_SEQ_ENTRY
:
case
ES_DONE_WITH_FLOW_SEQ_ENTRY
:
EmitSeparationIfNecessary
();
m_stream
<<
','
;
m_stream
<<
','
;
m_pState
->
RequireSoftSeparation
();
m_pState
->
RequireSoftSeparation
();
m_pState
->
SwitchState
(
ES_WAITING_FOR_FLOW_SEQ_ENTRY
);
m_pState
->
SwitchState
(
ES_WAITING_FOR_FLOW_SEQ_ENTRY
);
...
@@ -221,9 +222,9 @@ namespace YAML
...
@@ -221,9 +222,9 @@ namespace YAML
m_pState
->
SetError
(
ErrorMsg
::
EXPECTED_KEY_TOKEN
);
m_pState
->
SetError
(
ErrorMsg
::
EXPECTED_KEY_TOKEN
);
return
true
;
return
true
;
case
ES_WAITING_FOR_FLOW_MAP_KEY
:
case
ES_WAITING_FOR_FLOW_MAP_KEY
:
EmitSeparationIfNecessary
();
m_pState
->
SwitchState
(
ES_WRITING_FLOW_MAP_KEY
);
m_pState
->
SwitchState
(
ES_WRITING_FLOW_MAP_KEY
);
if
(
m_pState
->
CurrentlyInLongKey
())
{
if
(
m_pState
->
CurrentlyInLongKey
())
{
EmitSeparationIfNecessary
();
m_stream
<<
'?'
;
m_stream
<<
'?'
;
m_pState
->
RequireSoftSeparation
();
m_pState
->
RequireSoftSeparation
();
}
}
...
@@ -234,6 +235,7 @@ namespace YAML
...
@@ -234,6 +235,7 @@ namespace YAML
m_pState
->
SetError
(
ErrorMsg
::
EXPECTED_VALUE_TOKEN
);
m_pState
->
SetError
(
ErrorMsg
::
EXPECTED_VALUE_TOKEN
);
return
true
;
return
true
;
case
ES_WAITING_FOR_FLOW_MAP_VALUE
:
case
ES_WAITING_FOR_FLOW_MAP_VALUE
:
EmitSeparationIfNecessary
();
m_stream
<<
':'
;
m_stream
<<
':'
;
m_pState
->
RequireSoftSeparation
();
m_pState
->
RequireSoftSeparation
();
m_pState
->
SwitchState
(
ES_WRITING_FLOW_MAP_VALUE
);
m_pState
->
SwitchState
(
ES_WRITING_FLOW_MAP_VALUE
);
...
@@ -496,6 +498,7 @@ namespace YAML
...
@@ -496,6 +498,7 @@ namespace YAML
}
else
if
(
flowType
==
FT_FLOW
)
{
}
else
if
(
flowType
==
FT_FLOW
)
{
// Note: flow maps are allowed to be empty
// Note: flow maps are allowed to be empty
assert
(
curState
==
ES_DONE_WITH_FLOW_MAP_VALUE
||
curState
==
ES_WAITING_FOR_FLOW_MAP_ENTRY
);
assert
(
curState
==
ES_DONE_WITH_FLOW_MAP_VALUE
||
curState
==
ES_WAITING_FOR_FLOW_MAP_ENTRY
);
EmitSeparationIfNecessary
();
m_stream
<<
"}"
;
m_stream
<<
"}"
;
}
else
}
else
assert
(
false
);
assert
(
false
);
...
@@ -526,6 +529,7 @@ namespace YAML
...
@@ -526,6 +529,7 @@ namespace YAML
m_pState
->
UnsetSeparation
();
m_pState
->
UnsetSeparation
();
m_pState
->
SwitchState
(
ES_WAITING_FOR_BLOCK_MAP_KEY
);
m_pState
->
SwitchState
(
ES_WAITING_FOR_BLOCK_MAP_KEY
);
}
else
if
(
flowType
==
FT_FLOW
)
{
}
else
if
(
flowType
==
FT_FLOW
)
{
EmitSeparationIfNecessary
();
if
(
curState
==
ES_DONE_WITH_FLOW_MAP_VALUE
)
{
if
(
curState
==
ES_DONE_WITH_FLOW_MAP_VALUE
)
{
m_stream
<<
','
;
m_stream
<<
','
;
m_pState
->
RequireSoftSeparation
();
m_pState
->
RequireSoftSeparation
();
...
@@ -796,8 +800,12 @@ namespace YAML
...
@@ -796,8 +800,12 @@ namespace YAML
if
(
!
good
())
if
(
!
good
())
return
*
this
;
return
*
this
;
if
(
m_stream
.
col
()
>
0
)
m_stream
<<
Indentation
(
m_pState
->
GetPreCommentIndent
());
m_stream
<<
Indentation
(
m_pState
->
GetPreCommentIndent
());
Utils
::
WriteComment
(
m_stream
,
comment
.
content
,
m_pState
->
GetPostCommentIndent
());
Utils
::
WriteComment
(
m_stream
,
comment
.
content
,
m_pState
->
GetPostCommentIndent
());
m_pState
->
RequireHardSeparation
();
m_pState
->
ForceHardSeparation
();
return
*
this
;
return
*
this
;
}
}
...
...
src/emitterutils.cpp
View file @
bacb74e8
...
@@ -267,7 +267,7 @@ namespace YAML
...
@@ -267,7 +267,7 @@ namespace YAML
bool
WriteComment
(
ostream
&
out
,
const
std
::
string
&
str
,
int
postCommentIndent
)
bool
WriteComment
(
ostream
&
out
,
const
std
::
string
&
str
,
int
postCommentIndent
)
{
{
unsigned
curIndent
=
out
.
col
();
const
unsigned
curIndent
=
out
.
col
();
out
<<
"#"
<<
Indentation
(
postCommentIndent
);
out
<<
"#"
<<
Indentation
(
postCommentIndent
);
int
codePoint
;
int
codePoint
;
for
(
std
::
string
::
const_iterator
i
=
str
.
begin
();
for
(
std
::
string
::
const_iterator
i
=
str
.
begin
();
...
...
test/emittertests.cpp
View file @
bacb74e8
...
@@ -504,6 +504,40 @@ namespace Test
...
@@ -504,6 +504,40 @@ namespace Test
desiredOutput
=
"? long key # long key
\n
: value"
;
desiredOutput
=
"? long key # long key
\n
: value"
;
}
}
void
InitialComment
(
YAML
::
Emitter
&
out
,
std
::
string
&
desiredOutput
)
{
out
<<
YAML
::
Comment
(
"A comment describing the purpose of the file."
);
out
<<
YAML
::
BeginMap
<<
YAML
::
Key
<<
"key"
<<
YAML
::
Value
<<
"value"
<<
YAML
::
EndMap
;
desiredOutput
=
"# A comment describing the purpose of the file.
\n
key: value"
;
}
void
InitialCommentWithDocIndicator
(
YAML
::
Emitter
&
out
,
std
::
string
&
desiredOutput
)
{
out
<<
YAML
::
BeginDoc
<<
YAML
::
Comment
(
"A comment describing the purpose of the file."
);
out
<<
YAML
::
BeginMap
<<
YAML
::
Key
<<
"key"
<<
YAML
::
Value
<<
"value"
<<
YAML
::
EndMap
;
desiredOutput
=
"---
\n
# A comment describing the purpose of the file.
\n
key: value"
;
}
void
CommentInFlowSeq
(
YAML
::
Emitter
&
out
,
std
::
string
&
desiredOutput
)
{
out
<<
YAML
::
Flow
<<
YAML
::
BeginSeq
<<
"foo"
<<
YAML
::
Comment
(
"foo!"
)
<<
"bar"
<<
YAML
::
EndSeq
;
desiredOutput
=
"[foo # foo!
\n
, bar]"
;
}
void
CommentInFlowMap
(
YAML
::
Emitter
&
out
,
std
::
string
&
desiredOutput
)
{
out
<<
YAML
::
Flow
<<
YAML
::
BeginMap
;
out
<<
YAML
::
Key
<<
"foo"
<<
YAML
::
Comment
(
"foo!"
)
<<
YAML
::
Value
<<
"foo value"
;
out
<<
YAML
::
Key
<<
"bar"
<<
YAML
::
Value
<<
"bar value"
<<
YAML
::
Comment
(
"bar!"
);
out
<<
YAML
::
Key
<<
"baz"
<<
YAML
::
Comment
(
"baz!"
)
<<
YAML
::
Value
<<
"baz value"
<<
YAML
::
Comment
(
"baz!"
);
out
<<
YAML
::
EndMap
;
desiredOutput
=
"{foo # foo!
\n
: foo value, bar: bar value # bar!
\n
, baz # baz!
\n
: baz value # baz!
\n
}"
;
}
void
Indentation
(
YAML
::
Emitter
&
out
,
std
::
string
&
desiredOutput
)
void
Indentation
(
YAML
::
Emitter
&
out
,
std
::
string
&
desiredOutput
)
{
{
out
<<
YAML
::
Indent
(
4
);
out
<<
YAML
::
Indent
(
4
);
...
@@ -980,6 +1014,10 @@ namespace Test
...
@@ -980,6 +1014,10 @@ namespace Test
RunEmitterTest
(
&
Emitter
::
SimpleComment
,
"simple comment"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
SimpleComment
,
"simple comment"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
MultiLineComment
,
"multi-line comment"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
MultiLineComment
,
"multi-line comment"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
ComplexComments
,
"complex comments"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
ComplexComments
,
"complex comments"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
InitialComment
,
"initial comment"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
InitialCommentWithDocIndicator
,
"initial comment with doc indicator"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
CommentInFlowSeq
,
"comment in flow seq"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
CommentInFlowMap
,
"comment in flow map"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
Indentation
,
"indentation"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
Indentation
,
"indentation"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
SimpleGlobalSettings
,
"simple global settings"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
SimpleGlobalSettings
,
"simple global settings"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
ComplexGlobalSettings
,
"complex global settings"
,
passed
,
total
);
RunEmitterTest
(
&
Emitter
::
ComplexGlobalSettings
,
"complex global settings"
,
passed
,
total
);
...
...
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