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
91eac5d9
Commit
91eac5d9
authored
May 21, 2012
by
Jesse Beder
Browse files
Implemented block seq and block map indentation/newlines
parent
35d827f1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
1 deletion
+67
-1
src/emitter.cpp
src/emitter.cpp
+64
-1
util/sandbox.cpp
util/sandbox.cpp
+3
-0
No files found.
src/emitter.cpp
View file @
91eac5d9
...
@@ -304,6 +304,8 @@ namespace YAML
...
@@ -304,6 +304,8 @@ namespace YAML
void
Emitter
::
BlockSeqPrepareNode
(
EmitterNodeType
::
value
child
)
void
Emitter
::
BlockSeqPrepareNode
(
EmitterNodeType
::
value
child
)
{
{
const
unsigned
curIndent
=
m_pState
->
CurIndent
();
const
unsigned
curIndent
=
m_pState
->
CurIndent
();
const
unsigned
nextIndent
=
curIndent
+
m_pState
->
CurGroupIndent
();
if
(
!
m_pState
->
HasTag
()
&&
!
m_pState
->
HasAnchor
())
{
if
(
!
m_pState
->
HasTag
()
&&
!
m_pState
->
HasAnchor
())
{
if
(
m_pState
->
CurGroupChildCount
()
>
0
)
{
if
(
m_pState
->
CurGroupChildCount
()
>
0
)
{
m_stream
<<
"
\n
"
;
m_stream
<<
"
\n
"
;
...
@@ -311,6 +313,23 @@ namespace YAML
...
@@ -311,6 +313,23 @@ namespace YAML
m_stream
<<
IndentTo
(
curIndent
);
m_stream
<<
IndentTo
(
curIndent
);
m_stream
<<
"-"
;
m_stream
<<
"-"
;
}
}
switch
(
child
)
{
case
EmitterNodeType
::
None
:
case
EmitterNodeType
::
Scalar
:
case
EmitterNodeType
::
FlowSeq
:
case
EmitterNodeType
::
FlowMap
:
if
(
m_stream
.
col
()
<
nextIndent
)
m_stream
<<
IndentTo
(
nextIndent
);
else
m_stream
<<
" "
;
break
;
case
EmitterNodeType
::
BlockSeq
:
m_stream
<<
"
\n
"
;
break
;
case
EmitterNodeType
::
BlockMap
:
break
;
}
}
}
void
Emitter
::
FlowMapPrepareNode
(
EmitterNodeType
::
value
child
)
void
Emitter
::
FlowMapPrepareNode
(
EmitterNodeType
::
value
child
)
...
@@ -319,15 +338,59 @@ namespace YAML
...
@@ -319,15 +338,59 @@ namespace YAML
void
Emitter
::
BlockMapPrepareNode
(
EmitterNodeType
::
value
child
)
void
Emitter
::
BlockMapPrepareNode
(
EmitterNodeType
::
value
child
)
{
{
if
(
!
m_pState
->
HasTag
()
&&
!
m_pState
->
HasAnchor
())
{
const
unsigned
curIndent
=
m_pState
->
CurIndent
();
const
unsigned
nextIndent
=
curIndent
+
m_pState
->
CurGroupIndent
();
const
std
::
size_t
childCount
=
m_pState
->
CurGroupChildCount
();
const
std
::
size_t
childCount
=
m_pState
->
CurGroupChildCount
();
if
(
!
m_pState
->
HasTag
()
&&
!
m_pState
->
HasAnchor
())
{
if
(
childCount
%
2
==
0
)
{
if
(
childCount
%
2
==
0
)
{
// key
// key
if
(
childCount
>
0
)
{
if
(
childCount
>
0
)
{
m_stream
<<
"
\n
"
;
m_stream
<<
"
\n
"
;
}
}
if
(
false
/* long key */
)
{
}
}
else
{
}
else
{
// value
// value
if
(
false
/* was long key */
)
{
}
else
{
m_stream
<<
":"
;
}
}
}
if
(
childCount
%
2
==
0
)
{
// key
switch
(
child
)
{
case
EmitterNodeType
::
None
:
case
EmitterNodeType
::
Scalar
:
case
EmitterNodeType
::
FlowSeq
:
case
EmitterNodeType
::
FlowMap
:
if
(
m_stream
.
col
()
<
curIndent
)
m_stream
<<
IndentTo
(
curIndent
);
else
m_stream
<<
" "
;
break
;
case
EmitterNodeType
::
BlockSeq
:
case
EmitterNodeType
::
BlockMap
:
break
;
}
}
else
{
// value
switch
(
child
)
{
case
EmitterNodeType
::
None
:
case
EmitterNodeType
::
Scalar
:
case
EmitterNodeType
::
FlowSeq
:
case
EmitterNodeType
::
FlowMap
:
if
(
m_stream
.
col
()
<
nextIndent
)
m_stream
<<
IndentTo
(
nextIndent
);
else
m_stream
<<
" "
;
break
;
case
EmitterNodeType
::
BlockSeq
:
case
EmitterNodeType
::
BlockMap
:
m_stream
<<
"
\n
"
;
break
;
}
}
}
}
}
}
...
...
util/sandbox.cpp
View file @
91eac5d9
...
@@ -7,6 +7,9 @@ int main()
...
@@ -7,6 +7,9 @@ int main()
out
<<
YAML
::
BeginSeq
;
out
<<
YAML
::
BeginSeq
;
out
<<
"foo"
;
out
<<
"foo"
;
out
<<
"bar"
;
out
<<
"bar"
;
out
<<
YAML
::
BeginMap
;
out
<<
"a"
<<
"b"
<<
"c"
<<
"d"
;
out
<<
YAML
::
EndMap
;
out
<<
YAML
::
EndSeq
;
out
<<
YAML
::
EndSeq
;
std
::
cout
<<
out
.
c_str
()
<<
"
\n
"
;
std
::
cout
<<
out
.
c_str
()
<<
"
\n
"
;
...
...
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