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
dacc6319
Commit
dacc6319
authored
Jul 05, 2008
by
Jesse Beder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrote the output so that it emits correct YAML.
Fixed a bug in the last newline of a block folded scalar.
parent
d98007b0
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
99 additions
and
145 deletions
+99
-145
content.h
+1
-1
main.cpp
+1
-4
map.cpp
+16
-11
map.h
+1
-1
node.cpp
+22
-14
node.h
+4
-1
scalar.cpp
+12
-7
scalar.h
+1
-1
scanscalar.cpp
+6
-1
sequence.cpp
+16
-6
sequence.h
+1
-1
test.yaml
+18
-97
No files found.
content.h
View file @
dacc6319
...
@@ -19,7 +19,7 @@ namespace YAML
...
@@ -19,7 +19,7 @@ namespace YAML
virtual
~
Content
();
virtual
~
Content
();
virtual
void
Parse
(
Scanner
*
pScanner
,
const
ParserState
&
state
)
=
0
;
virtual
void
Parse
(
Scanner
*
pScanner
,
const
ParserState
&
state
)
=
0
;
virtual
void
Write
(
std
::
ostream
&
out
,
int
indent
)
=
0
;
virtual
void
Write
(
std
::
ostream
&
out
,
int
indent
,
bool
startedLine
,
bool
onlyOneCharOnLine
)
=
0
;
virtual
bool
GetBegin
(
std
::
vector
<
Node
*>::
const_iterator
&
it
)
const
{
return
false
;
}
virtual
bool
GetBegin
(
std
::
vector
<
Node
*>::
const_iterator
&
it
)
const
{
return
false
;
}
virtual
bool
GetBegin
(
std
::
map
<
Node
*
,
Node
*>::
const_iterator
&
it
)
const
{
return
false
;
}
virtual
bool
GetBegin
(
std
::
map
<
Node
*
,
Node
*>::
const_iterator
&
it
)
const
{
return
false
;
}
...
...
main.cpp
View file @
dacc6319
...
@@ -73,10 +73,7 @@ int main()
...
@@ -73,10 +73,7 @@ int main()
YAML
::
Node
doc
;
YAML
::
Node
doc
;
parser
.
GetNextDocument
(
doc
);
parser
.
GetNextDocument
(
doc
);
std
::
cout
<<
doc
;
Level
level
;
doc
>>
level
;
std
::
cout
<<
level
;
}
catch
(
YAML
::
Exception
&
)
{
}
catch
(
YAML
::
Exception
&
)
{
std
::
cout
<<
"Error parsing the yaml!
\n
"
;
std
::
cout
<<
"Error parsing the yaml!
\n
"
;
}
}
...
...
map.cpp
View file @
dacc6319
...
@@ -125,22 +125,27 @@ namespace YAML
...
@@ -125,22 +125,27 @@ namespace YAML
}
}
}
}
void
Map
::
Write
(
std
::
ostream
&
out
,
int
indent
)
void
Map
::
Write
(
std
::
ostream
&
out
,
int
indent
,
bool
startedLine
,
bool
onlyOneCharOnLine
)
{
{
for
(
int
i
=
0
;
i
<
indent
;
i
++
)
if
(
startedLine
&&
!
onlyOneCharOnLine
)
out
<<
" "
;
out
<<
std
::
endl
;
out
<<
"{map}
\n
"
;
for
(
node_map
::
const_iterator
it
=
m_data
.
begin
();
it
!=
m_data
.
end
();
++
it
)
{
for
(
node_map
::
const_iterator
it
=
m_data
.
begin
();
it
!=
m_data
.
end
();
++
it
)
{
for
(
int
i
=
0
;
i
<
indent
+
1
;
i
++
)
if
((
startedLine
&&
!
onlyOneCharOnLine
)
||
it
!=
m_data
.
begin
())
{
out
<<
" "
;
for
(
int
i
=
0
;
i
<
indent
;
i
++
)
out
<<
"{key}
\n
"
;
out
<<
"
"
;
it
->
first
->
Write
(
out
,
indent
+
2
);
}
for
(
int
i
=
0
;
i
<
indent
+
1
;
i
++
)
out
<<
"? "
;
it
->
first
->
Write
(
out
,
indent
+
1
,
true
,
it
!=
m_data
.
begin
()
||
!
startedLine
||
onlyOneCharOnLine
);
for
(
int
i
=
0
;
i
<
indent
;
i
++
)
out
<<
" "
;
out
<<
" "
;
out
<<
"
{value}
\n
"
;
out
<<
"
:
"
;
it
->
second
->
Write
(
out
,
indent
+
2
);
it
->
second
->
Write
(
out
,
indent
+
1
,
true
,
true
);
}
}
if
(
m_data
.
empty
())
out
<<
std
::
endl
;
}
}
}
}
map.h
View file @
dacc6319
...
@@ -17,7 +17,7 @@ namespace YAML
...
@@ -17,7 +17,7 @@ namespace YAML
virtual
bool
GetBegin
(
std
::
map
<
Node
*
,
Node
*>::
const_iterator
&
it
)
const
;
virtual
bool
GetBegin
(
std
::
map
<
Node
*
,
Node
*>::
const_iterator
&
it
)
const
;
virtual
bool
GetEnd
(
std
::
map
<
Node
*
,
Node
*>::
const_iterator
&
it
)
const
;
virtual
bool
GetEnd
(
std
::
map
<
Node
*
,
Node
*>::
const_iterator
&
it
)
const
;
virtual
void
Parse
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
virtual
void
Parse
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
virtual
void
Write
(
std
::
ostream
&
out
,
int
indent
);
virtual
void
Write
(
std
::
ostream
&
out
,
int
indent
,
bool
startedLine
,
bool
onlyOneCharOnLine
);
private
:
private
:
void
ParseBlock
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
void
ParseBlock
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
...
...
node.cpp
View file @
dacc6319
...
@@ -112,28 +112,30 @@ namespace YAML
...
@@ -112,28 +112,30 @@ namespace YAML
pScanner
->
PopNextToken
();
pScanner
->
PopNextToken
();
}
}
void
Node
::
Write
(
std
::
ostream
&
out
,
int
indent
)
void
Node
::
Write
(
std
::
ostream
&
out
,
int
indent
,
bool
startedLine
,
bool
onlyOneCharOnLine
)
const
{
{
if
(
m_tag
!=
""
)
{
// write anchor/alias
for
(
int
i
=
0
;
i
<
indent
;
i
++
)
out
<<
" "
;
out
<<
"{tag: "
<<
m_tag
<<
"}
\n
"
;
}
if
(
m_anchor
!=
""
)
{
if
(
m_anchor
!=
""
)
{
for
(
int
i
=
0
;
i
<
indent
;
i
++
)
out
<<
" "
;
if
(
m_alias
)
if
(
m_alias
)
out
<<
"
{alias: "
<<
m_anchor
<<
"}
\n
"
;
out
<<
"
*
"
;
else
else
out
<<
"{anchor: "
<<
m_anchor
<<
"}
\n
"
;
out
<<
"&"
;
out
<<
m_anchor
<<
" "
;
startedLine
=
true
;
onlyOneCharOnLine
=
false
;
}
// write tag
if
(
m_tag
!=
""
)
{
out
<<
"!<"
<<
m_tag
<<
"> "
;
startedLine
=
true
;
onlyOneCharOnLine
=
false
;
}
}
if
(
!
m_pContent
)
{
if
(
!
m_pContent
)
{
for
(
int
i
=
0
;
i
<
indent
;
i
++
)
out
<<
std
::
endl
;
out
<<
" "
;
out
<<
"{no content}
\n
"
;
}
else
{
}
else
{
m_pContent
->
Write
(
out
,
indent
);
m_pContent
->
Write
(
out
,
indent
,
startedLine
,
onlyOneCharOnLine
);
}
}
}
}
...
@@ -266,4 +268,10 @@ namespace YAML
...
@@ -266,4 +268,10 @@ namespace YAML
node
.
m_pContent
->
Read
(
c
);
node
.
m_pContent
->
Read
(
c
);
}
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
Node
&
node
)
{
node
.
Write
(
out
,
0
,
false
,
false
);
return
out
;
}
}
}
node.h
View file @
dacc6319
...
@@ -46,7 +46,7 @@ namespace YAML
...
@@ -46,7 +46,7 @@ namespace YAML
void
Clear
();
void
Clear
();
void
Parse
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
void
Parse
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
void
Write
(
std
::
ostream
&
out
,
int
indent
)
;
void
Write
(
std
::
ostream
&
out
,
int
indent
,
bool
startedLine
,
bool
onlyOneCharOnLine
)
const
;
// accessors
// accessors
Iterator
begin
()
const
;
Iterator
begin
()
const
;
...
@@ -92,6 +92,9 @@ namespace YAML
...
@@ -92,6 +92,9 @@ namespace YAML
friend
void
operator
>>
(
const
Node
&
node
,
double
&
d
);
friend
void
operator
>>
(
const
Node
&
node
,
double
&
d
);
friend
void
operator
>>
(
const
Node
&
node
,
char
&
c
);
friend
void
operator
>>
(
const
Node
&
node
,
char
&
c
);
// insertion
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
Node
&
node
);
private
:
private
:
void
ParseHeader
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
void
ParseHeader
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
void
ParseTag
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
void
ParseTag
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
...
...
scalar.cpp
View file @
dacc6319
...
@@ -21,14 +21,19 @@ namespace YAML
...
@@ -21,14 +21,19 @@ namespace YAML
delete
pToken
;
delete
pToken
;
}
}
void
Scalar
::
Write
(
std
::
ostream
&
out
,
int
indent
)
void
Scalar
::
Write
(
std
::
ostream
&
out
,
int
indent
,
bool
startedLine
,
bool
onlyOneCharOnLine
)
{
{
for
(
int
i
=
0
;
i
<
indent
;
i
++
)
out
<<
"
\"
"
;
out
<<
" "
;
for
(
unsigned
i
=
0
;
i
<
m_data
.
size
();
i
++
)
{
out
<<
"{scalar}
\n
"
;
switch
(
m_data
[
i
])
{
for
(
int
i
=
0
;
i
<
indent
;
i
++
)
case
'\\'
:
out
<<
"
\\\\
"
;
break
;
out
<<
" "
;
case
'\t'
:
out
<<
"
\\
t"
;
break
;
out
<<
m_data
<<
std
::
endl
;
case
'\n'
:
out
<<
"
\\
n"
;
break
;
case
'\r'
:
out
<<
"
\\
r"
;
break
;
default
:
out
<<
m_data
[
i
];
break
;
}
}
out
<<
"
\"\n
"
;
}
}
void
Scalar
::
Read
(
std
::
string
&
s
)
void
Scalar
::
Read
(
std
::
string
&
s
)
...
...
scalar.h
View file @
dacc6319
...
@@ -12,7 +12,7 @@ namespace YAML
...
@@ -12,7 +12,7 @@ namespace YAML
virtual
~
Scalar
();
virtual
~
Scalar
();
virtual
void
Parse
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
virtual
void
Parse
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
virtual
void
Write
(
std
::
ostream
&
out
,
int
indent
);
virtual
void
Write
(
std
::
ostream
&
out
,
int
indent
,
bool
startedLine
,
bool
onlyOneCharOnLine
);
// extraction
// extraction
virtual
void
Read
(
std
::
string
&
s
);
virtual
void
Read
(
std
::
string
&
s
);
...
...
scanscalar.cpp
View file @
dacc6319
...
@@ -110,7 +110,12 @@ namespace YAML
...
@@ -110,7 +110,12 @@ namespace YAML
bool
nextMoreIndented
=
(
INPUT
.
peek
()
==
' '
);
bool
nextMoreIndented
=
(
INPUT
.
peek
()
==
' '
);
// for block scalars, we always start with a newline, so we should ignore it (not fold or keep)
// for block scalars, we always start with a newline, so we should ignore it (not fold or keep)
if
(
pastOpeningBreak
)
{
bool
useNewLine
=
pastOpeningBreak
;
// and for folded scalars, we don't fold the very last newline to a space
if
(
params
.
fold
&&
!
emptyLine
&&
INPUT
.
column
<
params
.
indent
)
useNewLine
=
false
;
if
(
useNewLine
)
{
if
(
params
.
fold
&&
!
emptyLine
&&
!
nextEmptyLine
&&
!
moreIndented
&&
!
nextMoreIndented
)
if
(
params
.
fold
&&
!
emptyLine
&&
!
nextEmptyLine
&&
!
moreIndented
&&
!
nextMoreIndented
)
scalar
+=
" "
;
scalar
+=
" "
;
else
else
...
...
sequence.cpp
View file @
dacc6319
...
@@ -133,12 +133,22 @@ namespace YAML
...
@@ -133,12 +133,22 @@ namespace YAML
}
}
}
}
void
Sequence
::
Write
(
std
::
ostream
&
out
,
int
indent
)
void
Sequence
::
Write
(
std
::
ostream
&
out
,
int
indent
,
bool
startedLine
,
bool
onlyOneCharOnLine
)
{
{
for
(
int
i
=
0
;
i
<
indent
;
i
++
)
if
(
startedLine
&&
!
onlyOneCharOnLine
)
out
<<
" "
;
out
<<
std
::
endl
;
out
<<
"{sequence}
\n
"
;
for
(
unsigned
i
=
0
;
i
<
m_data
.
size
();
i
++
)
for
(
unsigned
i
=
0
;
i
<
m_data
.
size
();
i
++
)
{
m_data
[
i
]
->
Write
(
out
,
indent
+
1
);
if
((
startedLine
&&
!
onlyOneCharOnLine
)
||
i
>
0
)
{
for
(
int
j
=
0
;
j
<
indent
;
j
++
)
out
<<
" "
;
}
out
<<
"- "
;
m_data
[
i
]
->
Write
(
out
,
indent
+
1
,
true
,
i
>
0
||
!
startedLine
||
onlyOneCharOnLine
);
}
if
(
m_data
.
empty
())
out
<<
std
::
endl
;
}
}
}
}
sequence.h
View file @
dacc6319
...
@@ -20,7 +20,7 @@ namespace YAML
...
@@ -20,7 +20,7 @@ namespace YAML
virtual
unsigned
GetSize
()
const
;
virtual
unsigned
GetSize
()
const
;
virtual
void
Parse
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
virtual
void
Parse
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
virtual
void
Write
(
std
::
ostream
&
out
,
int
indent
);
virtual
void
Write
(
std
::
ostream
&
out
,
int
indent
,
bool
startedLine
,
bool
onlyOneCharOnLine
);
private
:
private
:
void
ParseBlock
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
void
ParseBlock
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
...
...
test.yaml
View file @
dacc6319
---
literal
:
|
model
:
Here's a literal scalar.
file
:
data/models/compound.model
That's a newline.
textures
:
data/materials/compound
rooms
:
Let's go...
-
name
:
"
Room
#1"
folded
:
>
pos
:
[
0
,
0
,
0
]
Here's a folded scalar that
size
:
[
1000
,
1000
,
500
]
wraps over to a newline.
height
:
500
stairtype
:
none
Let's go...
display
:
[]
regular
:
Here's a regular
pathfinding
:
scalar that keeps
tilesize
:
50
on wrapping...
size
:
[
24
,
24
]
map
:
|
-----------------------
Let's go!
-+++++++++++++++++++++-
and last key
:
so it doesn't go bonkers
-+-------------------+-
\ No newline at end of file
-+-------------------+-
-+-------------------+-
-+-------------------+-
-+-------------------+-
-+-------------------+-
-+-------------------+-
-+-------------------+-
-+---------------------
-+---------------------
-+---------------------
-+---------------------
-+-------------------+-
-+-------------------+-
-+-------------------+-
-+-------------------+-
-+-------------------+-
-+-------------------+-
-+-------------------+-
-+-------------------+-
-+++++++++++++++++++++-
-----------------------
-
name
:
Doorway
pos
:
[
1000
,
400
,
0
]
size
:
[
50
,
200
,
500
]
height
:
500
stairtype
:
none
display
:
[]
pathfinding
:
tilesize
:
50
size
:
[
5
,
9
]
map
:
|
-----
-+++-
-----
-----
-----
-----
-----
-+++-
-----
-
name
:
"
Room
#2"
pos
:
[
1050
,
0
,
0
]
size
:
[
1000
,
1000
,
500
]
height
:
500
stairtype
:
none
display
:
[]
pathfinding
:
tilesize
:
50
size
:
[
24
,
24
]
map
:
|
-----------------------
-+++++++++++++++++++++-
-+-------------------+-
-+-------------------+-
-+-------------------+-
-+-------------------+-
-+-------------------+-
-+-------------------+-
-+-------------------+-
-+-------------------+-
---------------------+-
---------------------+-
---------------------+-
---------------------+-
-+-------------------+-
-+-------------------+-
-+-------------------+-
-+-------------------+-
-+-------------------+-
-+-------------------+-
-+-------------------+-
-+-------------------+-
-+++++++++++++++++++++-
-----------------------
exits
:
-
room1
:
"
Room
#1"
room2
:
"
Room
#2"
dir
:
e
pos
:
[
400
,
600
]
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