Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yaml-cpp
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
yaml-cpp
Commits
3cae26a7
Commit
3cae26a7
authored
May 21, 2012
by
Jesse Beder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tags and anchors
parent
91eac5d9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
14 deletions
+69
-14
src/emitter.cpp
+54
-13
src/emitterstate.cpp
+10
-0
src/emitterstate.h
+3
-0
util/sandbox.cpp
+2
-1
No files found.
src/emitter.cpp
View file @
3cae26a7
...
...
@@ -284,17 +284,26 @@ namespace YAML
void
Emitter
::
PrepareTopNode
(
EmitterNodeType
::
value
child
)
{
const
bool
hasAnchor
=
m_pState
->
HasAnchor
();
const
bool
hasTag
=
m_pState
->
HasTag
();
if
(
!
hasAnchor
&&
!
hasTag
&&
m_stream
.
pos
()
>
0
)
{
if
(
!
m_pState
->
HasBegunNode
()
&&
m_stream
.
pos
()
>
0
)
{
EmitBeginDoc
();
}
// TODO: if we were writing null, and
// we wanted it blank, we wouldn't want a space
if
(
hasAnchor
||
hasTag
)
m_stream
<<
" "
;
switch
(
child
)
{
case
EmitterNodeType
:
:
None
:
case
EmitterNodeType
:
:
Scalar
:
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
)
...
...
@@ -306,7 +315,7 @@ namespace YAML
const
unsigned
curIndent
=
m_pState
->
CurIndent
();
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
)
{
m_stream
<<
"
\n
"
;
}
...
...
@@ -342,7 +351,7 @@ namespace YAML
const
unsigned
nextIndent
=
curIndent
+
m_pState
->
CurGroupIndent
();
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
)
{
// key
if
(
childCount
>
0
)
{
...
...
@@ -507,8 +516,20 @@ namespace YAML
{
if
(
!
good
())
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
;
}
...
...
@@ -517,9 +538,29 @@ namespace YAML
{
if
(
!
good
())
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
;
}
...
...
src/emitterstate.cpp
View file @
3cae26a7
...
...
@@ -43,6 +43,16 @@ namespace YAML
SetMapKeyFormat
(
value
,
FmtScope
::
Local
);
}
void
EmitterState
::
SetAnchor
()
{
m_hasAnchor
=
true
;
}
void
EmitterState
::
SetTag
()
{
m_hasTag
=
true
;
}
void
EmitterState
::
BeginNode
()
{
if
(
!
m_groups
.
empty
())
...
...
src/emitterstate.h
View file @
3cae26a7
...
...
@@ -34,6 +34,8 @@ namespace YAML
void
SetError
(
const
std
::
string
&
error
)
{
throw
std
::
runtime_error
(
error
);
m_isGood
=
false
;
m_lastError
=
error
;
}
// node handling
void
SetAnchor
();
void
SetTag
();
void
BeginScalar
();
void
BeginGroup
(
GroupType
::
value
type
);
void
EndGroup
(
GroupType
::
value
type
);
...
...
@@ -49,6 +51,7 @@ namespace YAML
int
CurIndent
()
const
{
return
m_curIndent
;
}
bool
HasAnchor
()
const
{
return
m_hasAnchor
;
}
bool
HasTag
()
const
{
return
m_hasTag
;
}
bool
HasBegunNode
()
const
{
return
m_hasAnchor
||
m_hasTag
;
}
void
ClearModifiedSettings
();
...
...
util/sandbox.cpp
View file @
3cae26a7
...
...
@@ -4,9 +4,10 @@
int
main
()
{
YAML
::
Emitter
out
;
out
<<
YAML
::
Anchor
(
"monkey"
);
out
<<
YAML
::
BeginSeq
;
out
<<
"foo"
;
out
<<
"bar"
;
out
<<
YAML
::
LocalTag
(
"hi"
)
<<
"bar"
;
out
<<
YAML
::
BeginMap
;
out
<<
"a"
<<
"b"
<<
"c"
<<
"d"
;
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