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
41e4cd33
Commit
41e4cd33
authored
May 22, 2012
by
Jesse Beder
Browse files
Split block map simple/long key for both key/value
parent
952fe51c
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
109 additions
and
27 deletions
+109
-27
include/yaml-cpp/emitter.h
include/yaml-cpp/emitter.h
+4
-2
src/emitter.cpp
src/emitter.cpp
+74
-11
src/emitterstate.cpp
src/emitterstate.cpp
+21
-2
src/emitterstate.h
src/emitterstate.h
+4
-1
util/sandbox.cpp
util/sandbox.cpp
+6
-11
No files found.
include/yaml-cpp/emitter.h
View file @
41e4cd33
...
...
@@ -95,8 +95,10 @@ namespace YAML
void
BlockSeqPrepareNode
(
EmitterNodeType
::
value
child
);
void
FlowMapPrepareNode
(
EmitterNodeType
::
value
child
);
void
BlockMapPrepareNode
(
EmitterNodeType
::
value
child
);
void
BlockMapPrepareKey
(
EmitterNodeType
::
value
child
);
void
BlockMapPrepareValue
(
EmitterNodeType
::
value
child
);
void
BlockMapPrepareLongKey
(
EmitterNodeType
::
value
child
);
void
BlockMapPrepareSimpleKey
(
EmitterNodeType
::
value
child
);
void
BlockMapPrepareLongKeyValue
(
EmitterNodeType
::
value
child
);
void
BlockMapPrepareSimpleKeyValue
(
EmitterNodeType
::
value
child
);
void
SpaceOrIndentTo
(
bool
requireSpace
,
unsigned
indent
);
...
...
src/emitter.cpp
View file @
41e4cd33
...
...
@@ -360,13 +360,23 @@ namespace YAML
{
const
std
::
size_t
childCount
=
m_pState
->
CurGroupChildCount
();
if
(
childCount
%
2
==
0
)
BlockMapPrepareKey
(
child
);
if
(
childCount
%
2
==
0
)
{
if
(
m_pState
->
GetMapKeyFormat
()
==
LongKey
||
child
==
EmitterNodeType
::
BlockSeq
||
child
==
EmitterNodeType
::
BlockMap
)
m_pState
->
SetLongKey
();
if
(
m_pState
->
CurGroupLongKey
())
BlockMapPrepareLongKey
(
child
);
else
BlockMapPrepareSimpleKey
(
child
);
}
else
{
if
(
m_pState
->
CurGroupLongKey
())
BlockMapPrepareLongKeyValue
(
child
);
else
BlockMapPrepareValue
(
child
);
BlockMapPrepareSimpleKeyValue
(
child
);
}
}
void
Emitter
::
BlockMapPrepareKey
(
EmitterNodeType
::
value
child
)
void
Emitter
::
BlockMapPrepare
Long
Key
(
EmitterNodeType
::
value
child
)
{
const
unsigned
curIndent
=
m_pState
->
CurIndent
();
const
std
::
size_t
childCount
=
m_pState
->
CurGroupChildCount
();
...
...
@@ -378,8 +388,11 @@ namespace YAML
if
(
childCount
>
0
)
{
m_stream
<<
"
\n
"
;
}
if
(
false
/* long key */
)
{
if
(
m_stream
.
comment
())
{
m_stream
<<
"
\n
"
;
}
m_stream
<<
IndentTo
(
curIndent
);
m_stream
<<
"?"
;
}
switch
(
child
)
{
...
...
@@ -397,16 +410,66 @@ namespace YAML
}
}
void
Emitter
::
BlockMapPrepareValue
(
EmitterNodeType
::
value
child
)
void
Emitter
::
BlockMapPrepareSimpleKey
(
EmitterNodeType
::
value
child
)
{
const
unsigned
curIndent
=
m_pState
->
CurIndent
();
const
std
::
size_t
childCount
=
m_pState
->
CurGroupChildCount
();
if
(
child
==
EmitterNodeType
::
None
)
return
;
if
(
!
m_pState
->
HasBegunNode
())
{
if
(
childCount
>
0
)
{
m_stream
<<
"
\n
"
;
}
}
switch
(
child
)
{
case
EmitterNodeType
::
None
:
break
;
case
EmitterNodeType
::
Property
:
case
EmitterNodeType
::
Scalar
:
case
EmitterNodeType
::
FlowSeq
:
case
EmitterNodeType
::
FlowMap
:
SpaceOrIndentTo
(
m_pState
->
HasBegunContent
(),
curIndent
);
break
;
case
EmitterNodeType
::
BlockSeq
:
case
EmitterNodeType
::
BlockMap
:
break
;
}
}
void
Emitter
::
BlockMapPrepareLongKeyValue
(
EmitterNodeType
::
value
child
)
{
const
unsigned
curIndent
=
m_pState
->
CurIndent
();
const
unsigned
nextIndent
=
curIndent
+
m_pState
->
CurGroupIndent
();
if
(
!
m_pState
->
HasBegunNode
())
{
if
(
false
/* was long key */
)
{
}
else
{
m_stream
<<
":"
;
}
switch
(
child
)
{
case
EmitterNodeType
::
None
:
break
;
case
EmitterNodeType
::
Property
:
case
EmitterNodeType
::
Scalar
:
case
EmitterNodeType
::
FlowSeq
:
case
EmitterNodeType
::
FlowMap
:
SpaceOrIndentTo
(
true
,
nextIndent
);
break
;
case
EmitterNodeType
::
BlockSeq
:
case
EmitterNodeType
::
BlockMap
:
m_stream
<<
"
\n
"
;
break
;
}
}
void
Emitter
::
BlockMapPrepareSimpleKeyValue
(
EmitterNodeType
::
value
child
)
{
const
unsigned
curIndent
=
m_pState
->
CurIndent
();
const
unsigned
nextIndent
=
curIndent
+
m_pState
->
CurGroupIndent
();
if
(
!
m_pState
->
HasBegunNode
())
{
m_stream
<<
":"
;
}
switch
(
child
)
{
...
...
src/emitterstate.cpp
View file @
41e4cd33
...
...
@@ -58,12 +58,26 @@ namespace YAML
m_hasNonContent
=
true
;
}
void
EmitterState
::
S
tartedNode
()
void
EmitterState
::
S
etLongKey
()
{
assert
(
!
m_groups
.
empty
());
if
(
m_groups
.
empty
())
return
;
assert
(
m_groups
.
top
().
type
==
GroupType
::
Map
);
assert
(
m_groups
.
top
().
flowType
==
FlowType
::
Block
);
m_groups
.
top
().
longKey
=
true
;
}
void
EmitterState
::
StartedNode
()
{
if
(
m_groups
.
empty
())
{
m_docCount
++
;
else
}
else
{
m_groups
.
top
().
childCount
++
;
if
(
m_groups
.
top
().
childCount
%
2
==
0
)
m_groups
.
top
().
longKey
=
false
;
}
m_hasAnchor
=
false
;
m_hasTag
=
false
;
...
...
@@ -166,6 +180,11 @@ namespace YAML
return
m_groups
.
empty
()
?
m_docCount
:
m_groups
.
top
().
childCount
;
}
bool
EmitterState
::
CurGroupLongKey
()
const
{
return
m_groups
.
empty
()
?
false
:
m_groups
.
top
().
longKey
;
}
void
EmitterState
::
ClearModifiedSettings
()
{
m_modifiedSettings
.
clear
();
...
...
src/emitterstate.h
View file @
41e4cd33
...
...
@@ -37,6 +37,7 @@ namespace YAML
void
SetAnchor
();
void
SetTag
();
void
SetNonContent
();
void
SetLongKey
();
void
StartedScalar
();
void
StartedGroup
(
GroupType
::
value
type
);
void
EndedGroup
(
GroupType
::
value
type
);
...
...
@@ -48,6 +49,7 @@ namespace YAML
FlowType
::
value
CurGroupFlowType
()
const
;
int
CurGroupIndent
()
const
;
std
::
size_t
CurGroupChildCount
()
const
;
bool
CurGroupLongKey
()
const
;
int
CurIndent
()
const
{
return
m_curIndent
;
}
bool
HasAnchor
()
const
{
return
m_hasAnchor
;
}
...
...
@@ -127,12 +129,13 @@ namespace YAML
SettingChanges
m_globalModifiedSettings
;
struct
Group
{
explicit
Group
(
GroupType
::
value
type_
)
:
type
(
type_
),
indent
(
0
),
childCount
(
0
)
{}
explicit
Group
(
GroupType
::
value
type_
)
:
type
(
type_
),
indent
(
0
),
childCount
(
0
)
,
longKey
(
false
)
{}
GroupType
::
value
type
;
FlowType
::
value
flowType
;
int
indent
;
std
::
size_t
childCount
;
bool
longKey
;
SettingChanges
modifiedSettings
;
...
...
util/sandbox.cpp
View file @
41e4cd33
...
...
@@ -4,17 +4,12 @@
int
main
()
{
YAML
::
Emitter
out
;
out
<<
YAML
::
Comment
(
"Hello"
);
out
<<
YAML
::
BeginSeq
;
out
<<
YAML
::
Comment
(
"Hello"
);
out
<<
YAML
::
Anchor
(
"a"
)
<<
YAML
::
Comment
(
"anchor"
)
<<
"item 1"
<<
YAML
::
Comment
(
"a"
);
out
<<
YAML
::
BeginMap
<<
YAML
::
Comment
(
"b"
);
out
<<
"pens"
<<
YAML
::
Comment
(
"foo"
)
<<
2.3
<<
YAML
::
Comment
(
"bar"
);
out
<<
"pencils"
<<
15
;
out
<<
YAML
::
EndMap
<<
YAML
::
Comment
(
"monkey"
);
out
<<
"item 2"
;
out
<<
YAML
::
EndSeq
;
out
<<
YAML
::
Comment
(
"end"
);
out
<<
YAML
::
BeginMap
;
out
<<
YAML
::
BeginMap
;
out
<<
"a"
<<
"b"
;
out
<<
YAML
::
EndMap
;
out
<<
"c"
;
out
<<
YAML
::
EndMap
;
std
::
cout
<<
out
.
c_str
()
<<
"
\n
"
;
return
0
;
...
...
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