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
3cae26a7
Commit
3cae26a7
authored
May 21, 2012
by
Jesse Beder
Browse files
Added tags and anchors
parent
91eac5d9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
14 deletions
+69
-14
src/emitter.cpp
src/emitter.cpp
+54
-13
src/emitterstate.cpp
src/emitterstate.cpp
+10
-0
src/emitterstate.h
src/emitterstate.h
+3
-0
util/sandbox.cpp
util/sandbox.cpp
+2
-1
No files found.
src/emitter.cpp
View file @
3cae26a7
...
@@ -284,17 +284,26 @@ namespace YAML
...
@@ -284,17 +284,26 @@ namespace YAML
void
Emitter
::
PrepareTopNode
(
EmitterNodeType
::
value
child
)
void
Emitter
::
PrepareTopNode
(
EmitterNodeType
::
value
child
)
{
{
const
bool
hasAnchor
=
m_pState
->
HasAnchor
();
if
(
!
m_pState
->
HasBegunNode
()
&&
m_stream
.
pos
()
>
0
)
{
const
bool
hasTag
=
m_pState
->
HasTag
();
if
(
!
hasAnchor
&&
!
hasTag
&&
m_stream
.
pos
()
>
0
)
{
EmitBeginDoc
();
EmitBeginDoc
();
}
}
// TODO: if we were writing null, and
switch
(
child
)
{
// we wanted it blank, we wouldn't want a space
case
EmitterNodeType
::
None
:
if
(
hasAnchor
||
hasTag
)
case
EmitterNodeType
::
Scalar
:
m_stream
<<
" "
;
case
EmitterNodeType
::
FlowSeq
:
case
EmitterNodeType
::
FlowMap
:
// TODO: if we were writing null, and
// we wanted it blank, we wouldn't want a space
if
(
m_pState
->
HasBegunNode
())
m_stream
<<
" "
;
break
;
case
EmitterNodeType
::
BlockSeq
:
case
EmitterNodeType
::
BlockMap
:
if
(
m_pState
->
HasBegunNode
())
m_stream
<<
"
\n
"
;
break
;
}
}
}
void
Emitter
::
FlowSeqPrepareNode
(
EmitterNodeType
::
value
child
)
void
Emitter
::
FlowSeqPrepareNode
(
EmitterNodeType
::
value
child
)
...
@@ -306,7 +315,7 @@ namespace YAML
...
@@ -306,7 +315,7 @@ namespace YAML
const
unsigned
curIndent
=
m_pState
->
CurIndent
();
const
unsigned
curIndent
=
m_pState
->
CurIndent
();
const
unsigned
nextIndent
=
curIndent
+
m_pState
->
CurGroupIndent
();
const
unsigned
nextIndent
=
curIndent
+
m_pState
->
CurGroupIndent
();
if
(
!
m_pState
->
Has
Tag
()
&&
!
m_pState
->
HasAnchor
())
{
if
(
!
m_pState
->
Has
BegunNode
())
{
if
(
m_pState
->
CurGroupChildCount
()
>
0
)
{
if
(
m_pState
->
CurGroupChildCount
()
>
0
)
{
m_stream
<<
"
\n
"
;
m_stream
<<
"
\n
"
;
}
}
...
@@ -342,7 +351,7 @@ namespace YAML
...
@@ -342,7 +351,7 @@ namespace YAML
const
unsigned
nextIndent
=
curIndent
+
m_pState
->
CurGroupIndent
();
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
->
Has
Tag
()
&&
!
m_pState
->
HasAnchor
())
{
if
(
!
m_pState
->
Has
BegunNode
())
{
if
(
childCount
%
2
==
0
)
{
if
(
childCount
%
2
==
0
)
{
// key
// key
if
(
childCount
>
0
)
{
if
(
childCount
>
0
)
{
...
@@ -507,8 +516,20 @@ namespace YAML
...
@@ -507,8 +516,20 @@ namespace YAML
{
{
if
(
!
good
())
if
(
!
good
())
return
*
this
;
return
*
this
;
if
(
m_pState
->
HasAnchor
())
{
m_pState
->
SetError
(
ErrorMsg
::
INVALID_ANCHOR
);
return
*
this
;
}
m_pState
->
BeginScalar
();
PrepareNode
(
EmitterNodeType
::
None
);
if
(
!
Utils
::
WriteAnchor
(
m_stream
,
anchor
.
content
))
{
m_pState
->
SetError
(
ErrorMsg
::
INVALID_ANCHOR
);
return
*
this
;
}
m_pState
->
SetAnchor
();
return
*
this
;
return
*
this
;
}
}
...
@@ -517,9 +538,29 @@ namespace YAML
...
@@ -517,9 +538,29 @@ namespace YAML
{
{
if
(
!
good
())
if
(
!
good
())
return
*
this
;
return
*
this
;
m_pState
->
BeginScalar
();
if
(
m_pState
->
HasTag
())
{
m_pState
->
SetError
(
ErrorMsg
::
INVALID_TAG
);
return
*
this
;
}
PrepareNode
(
EmitterNodeType
::
None
);
bool
success
=
false
;
if
(
tag
.
type
==
_Tag
::
Type
::
Verbatim
)
success
=
Utils
::
WriteTag
(
m_stream
,
tag
.
content
,
true
);
else
if
(
tag
.
type
==
_Tag
::
Type
::
PrimaryHandle
)
success
=
Utils
::
WriteTag
(
m_stream
,
tag
.
content
,
false
);
else
success
=
Utils
::
WriteTagWithPrefix
(
m_stream
,
tag
.
prefix
,
tag
.
content
);
if
(
!
success
)
{
m_pState
->
SetError
(
ErrorMsg
::
INVALID_TAG
);
return
*
this
;
}
m_pState
->
SetTag
();
return
*
this
;
return
*
this
;
}
}
...
...
src/emitterstate.cpp
View file @
3cae26a7
...
@@ -43,6 +43,16 @@ namespace YAML
...
@@ -43,6 +43,16 @@ namespace YAML
SetMapKeyFormat
(
value
,
FmtScope
::
Local
);
SetMapKeyFormat
(
value
,
FmtScope
::
Local
);
}
}
void
EmitterState
::
SetAnchor
()
{
m_hasAnchor
=
true
;
}
void
EmitterState
::
SetTag
()
{
m_hasTag
=
true
;
}
void
EmitterState
::
BeginNode
()
void
EmitterState
::
BeginNode
()
{
{
if
(
!
m_groups
.
empty
())
if
(
!
m_groups
.
empty
())
...
...
src/emitterstate.h
View file @
3cae26a7
...
@@ -34,6 +34,8 @@ namespace YAML
...
@@ -34,6 +34,8 @@ namespace YAML
void
SetError
(
const
std
::
string
&
error
)
{
throw
std
::
runtime_error
(
error
);
m_isGood
=
false
;
m_lastError
=
error
;
}
void
SetError
(
const
std
::
string
&
error
)
{
throw
std
::
runtime_error
(
error
);
m_isGood
=
false
;
m_lastError
=
error
;
}
// node handling
// node handling
void
SetAnchor
();
void
SetTag
();
void
BeginScalar
();
void
BeginScalar
();
void
BeginGroup
(
GroupType
::
value
type
);
void
BeginGroup
(
GroupType
::
value
type
);
void
EndGroup
(
GroupType
::
value
type
);
void
EndGroup
(
GroupType
::
value
type
);
...
@@ -49,6 +51,7 @@ namespace YAML
...
@@ -49,6 +51,7 @@ namespace YAML
int
CurIndent
()
const
{
return
m_curIndent
;
}
int
CurIndent
()
const
{
return
m_curIndent
;
}
bool
HasAnchor
()
const
{
return
m_hasAnchor
;
}
bool
HasAnchor
()
const
{
return
m_hasAnchor
;
}
bool
HasTag
()
const
{
return
m_hasTag
;
}
bool
HasTag
()
const
{
return
m_hasTag
;
}
bool
HasBegunNode
()
const
{
return
m_hasAnchor
||
m_hasTag
;
}
void
ClearModifiedSettings
();
void
ClearModifiedSettings
();
...
...
util/sandbox.cpp
View file @
3cae26a7
...
@@ -4,9 +4,10 @@
...
@@ -4,9 +4,10 @@
int
main
()
int
main
()
{
{
YAML
::
Emitter
out
;
YAML
::
Emitter
out
;
out
<<
YAML
::
Anchor
(
"monkey"
);
out
<<
YAML
::
BeginSeq
;
out
<<
YAML
::
BeginSeq
;
out
<<
"foo"
;
out
<<
"foo"
;
out
<<
"bar"
;
out
<<
YAML
::
LocalTag
(
"hi"
)
<<
"bar"
;
out
<<
YAML
::
BeginMap
;
out
<<
YAML
::
BeginMap
;
out
<<
"a"
<<
"b"
<<
"c"
<<
"d"
;
out
<<
"a"
<<
"b"
<<
"c"
<<
"d"
;
out
<<
YAML
::
EndMap
;
out
<<
YAML
::
EndMap
;
...
...
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