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
91163d22
Commit
91163d22
authored
Sep 05, 2009
by
Jesse Beder
Browse files
Allowed solo entries in a flow map to be read as keys with null value
parent
75477ade
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
113 additions
and
52 deletions
+113
-52
src/scanner.cpp
src/scanner.cpp
+10
-10
src/scanner.h
src/scanner.h
+9
-2
src/scantoken.cpp
src/scantoken.cpp
+31
-24
src/simplekey.cpp
src/simplekey.cpp
+19
-15
yaml-reader/parsertests.cpp
yaml-reader/parsertests.cpp
+40
-1
yaml-reader/tests.cpp
yaml-reader/tests.cpp
+2
-0
yaml-reader/tests.h
yaml-reader/tests.h
+2
-0
No files found.
src/scanner.cpp
View file @
91163d22
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
namespace
YAML
namespace
YAML
{
{
Scanner
::
Scanner
(
std
::
istream
&
in
)
Scanner
::
Scanner
(
std
::
istream
&
in
)
:
INPUT
(
in
),
m_startedStream
(
false
),
m_endedStream
(
false
),
m_simpleKeyAllowed
(
false
)
,
m_flowLevel
(
0
)
:
INPUT
(
in
),
m_startedStream
(
false
),
m_endedStream
(
false
),
m_simpleKeyAllowed
(
false
)
{
{
}
}
...
@@ -136,10 +136,10 @@ namespace YAML
...
@@ -136,10 +136,10 @@ namespace YAML
if
(
Exp
::
BlockEntry
.
Matches
(
INPUT
))
if
(
Exp
::
BlockEntry
.
Matches
(
INPUT
))
return
ScanBlockEntry
();
return
ScanBlockEntry
();
if
((
m_flowLevel
==
0
?
Exp
::
Key
:
Exp
::
KeyInFlow
).
Matches
(
INPUT
))
if
((
InBlockContext
()
?
Exp
::
Key
:
Exp
::
KeyInFlow
).
Matches
(
INPUT
))
return
ScanKey
();
return
ScanKey
();
if
((
m_flowLevel
==
0
?
Exp
::
Value
:
Exp
::
ValueInFlow
).
Matches
(
INPUT
))
if
((
InBlockContext
()
?
Exp
::
Value
:
Exp
::
ValueInFlow
).
Matches
(
INPUT
))
return
ScanValue
();
return
ScanValue
();
// alias/anchor
// alias/anchor
...
@@ -151,14 +151,14 @@ namespace YAML
...
@@ -151,14 +151,14 @@ namespace YAML
return
ScanTag
();
return
ScanTag
();
// special scalars
// special scalars
if
(
m_flowLevel
==
0
&&
(
INPUT
.
peek
()
==
Keys
::
LiteralScalar
||
INPUT
.
peek
()
==
Keys
::
FoldedScalar
))
if
(
InBlockContext
()
&&
(
INPUT
.
peek
()
==
Keys
::
LiteralScalar
||
INPUT
.
peek
()
==
Keys
::
FoldedScalar
))
return
ScanBlockScalar
();
return
ScanBlockScalar
();
if
(
INPUT
.
peek
()
==
'\''
||
INPUT
.
peek
()
==
'\"'
)
if
(
INPUT
.
peek
()
==
'\''
||
INPUT
.
peek
()
==
'\"'
)
return
ScanQuotedScalar
();
return
ScanQuotedScalar
();
// plain scalars
// plain scalars
if
((
m_flowLevel
==
0
?
Exp
::
PlainScalar
:
Exp
::
PlainScalarInFlow
).
Matches
(
INPUT
))
if
((
InBlockContext
()
?
Exp
::
PlainScalar
:
Exp
::
PlainScalarInFlow
).
Matches
(
INPUT
))
return
ScanPlainScalar
();
return
ScanPlainScalar
();
// don't know what it is!
// don't know what it is!
...
@@ -193,7 +193,7 @@ namespace YAML
...
@@ -193,7 +193,7 @@ namespace YAML
InvalidateSimpleKey
();
InvalidateSimpleKey
();
// new line - we may be able to accept a simple key now
// new line - we may be able to accept a simple key now
if
(
m_flowLevel
==
0
)
if
(
InBlockContext
()
)
m_simpleKeyAllowed
=
true
;
m_simpleKeyAllowed
=
true
;
}
}
}
}
...
@@ -213,7 +213,7 @@ namespace YAML
...
@@ -213,7 +213,7 @@ namespace YAML
if
(
ch
==
' '
)
if
(
ch
==
' '
)
return
true
;
return
true
;
if
(
ch
==
'\t'
&&
(
m_flowLevel
>=
0
||
!
m_simpleKeyAllowed
))
if
(
ch
==
'\t'
&&
(
InFlowContext
()
||
!
m_simpleKeyAllowed
))
return
true
;
return
true
;
return
false
;
return
false
;
...
@@ -251,7 +251,7 @@ namespace YAML
...
@@ -251,7 +251,7 @@ namespace YAML
Scanner
::
IndentMarker
*
Scanner
::
PushIndentTo
(
int
column
,
IndentMarker
::
INDENT_TYPE
type
)
Scanner
::
IndentMarker
*
Scanner
::
PushIndentTo
(
int
column
,
IndentMarker
::
INDENT_TYPE
type
)
{
{
// are we in flow?
// are we in flow?
if
(
m_flowLevel
>
0
)
if
(
InFlowContext
()
)
return
0
;
return
0
;
IndentMarker
indent
(
column
,
type
);
IndentMarker
indent
(
column
,
type
);
...
@@ -283,7 +283,7 @@ namespace YAML
...
@@ -283,7 +283,7 @@ namespace YAML
void
Scanner
::
PopIndentToHere
()
void
Scanner
::
PopIndentToHere
()
{
{
// are we in flow?
// are we in flow?
if
(
m_flowLevel
>
0
)
if
(
InFlowContext
()
)
return
;
return
;
// now pop away
// now pop away
...
@@ -304,7 +304,7 @@ namespace YAML
...
@@ -304,7 +304,7 @@ namespace YAML
void
Scanner
::
PopAllIndents
()
void
Scanner
::
PopAllIndents
()
{
{
// are we in flow?
// are we in flow?
if
(
m_flowLevel
>
0
)
if
(
InFlowContext
()
)
return
;
return
;
// now pop away
// now pop away
...
...
src/scanner.h
View file @
91163d22
...
@@ -43,6 +43,8 @@ namespace YAML
...
@@ -43,6 +43,8 @@ namespace YAML
bool
isValid
;
bool
isValid
;
Token
*
pStartToken
;
Token
*
pStartToken
;
};
};
enum
FLOW_MARKER
{
FLOW_MAP
,
FLOW_SEQ
};
private:
private:
// scanning
// scanning
...
@@ -51,6 +53,11 @@ namespace YAML
...
@@ -51,6 +53,11 @@ namespace YAML
void
ScanToNextToken
();
void
ScanToNextToken
();
void
StartStream
();
void
StartStream
();
void
EndStream
();
void
EndStream
();
bool
InFlowContext
()
const
{
return
!
m_flows
.
empty
();
}
bool
InBlockContext
()
const
{
return
m_flows
.
empty
();
}
int
GetFlowLevel
()
const
{
return
m_flows
.
size
();
}
IndentMarker
*
PushIndentTo
(
int
column
,
IndentMarker
::
INDENT_TYPE
type
);
IndentMarker
*
PushIndentTo
(
int
column
,
IndentMarker
::
INDENT_TYPE
type
);
void
PopIndentToHere
();
void
PopIndentToHere
();
void
PopAllIndents
();
void
PopAllIndents
();
...
@@ -58,6 +65,7 @@ namespace YAML
...
@@ -58,6 +65,7 @@ namespace YAML
int
GetTopIndent
()
const
;
int
GetTopIndent
()
const
;
// checking input
// checking input
bool
CanInsertPotentialSimpleKey
()
const
;
bool
ExistsActiveSimpleKey
()
const
;
bool
ExistsActiveSimpleKey
()
const
;
void
InsertPotentialSimpleKey
();
void
InsertPotentialSimpleKey
();
void
InvalidateSimpleKey
();
void
InvalidateSimpleKey
();
...
@@ -109,10 +117,9 @@ namespace YAML
...
@@ -109,10 +117,9 @@ namespace YAML
// state info
// state info
bool
m_startedStream
,
m_endedStream
;
bool
m_startedStream
,
m_endedStream
;
bool
m_simpleKeyAllowed
;
bool
m_simpleKeyAllowed
;
int
m_flowLevel
;
// number of unclosed '[' and '{' indicators
bool
m_isLastKeyValid
;
std
::
stack
<
SimpleKey
>
m_simpleKeys
;
std
::
stack
<
SimpleKey
>
m_simpleKeys
;
std
::
stack
<
IndentMarker
>
m_indents
;
std
::
stack
<
IndentMarker
>
m_indents
;
std
::
stack
<
FLOW_MARKER
>
m_flows
;
std
::
map
<
std
::
string
,
const
Node
*>
m_anchors
;
std
::
map
<
std
::
string
,
const
Node
*>
m_anchors
;
};
};
}
}
...
...
src/scantoken.cpp
View file @
91163d22
...
@@ -87,36 +87,50 @@ namespace YAML
...
@@ -87,36 +87,50 @@ namespace YAML
{
{
// flows can be simple keys
// flows can be simple keys
InsertPotentialSimpleKey
();
InsertPotentialSimpleKey
();
m_flowLevel
++
;
m_simpleKeyAllowed
=
true
;
m_simpleKeyAllowed
=
true
;
// eat
// eat
Mark
mark
=
INPUT
.
mark
();
Mark
mark
=
INPUT
.
mark
();
char
ch
=
INPUT
.
get
();
char
ch
=
INPUT
.
get
();
Token
::
TYPE
type
=
(
ch
==
Keys
::
FlowSeqStart
?
Token
::
FLOW_SEQ_START
:
Token
::
FLOW_MAP_START
);
FLOW_MARKER
flowType
=
(
ch
==
Keys
::
FlowSeqStart
?
FLOW_SEQ
:
FLOW_MAP
);
m_flows
.
push
(
flowType
);
Token
::
TYPE
type
=
(
flowType
==
FLOW_SEQ
?
Token
::
FLOW_SEQ_START
:
Token
::
FLOW_MAP_START
);
m_tokens
.
push
(
Token
(
type
,
mark
));
m_tokens
.
push
(
Token
(
type
,
mark
));
}
}
// FlowEnd
// FlowEnd
void
Scanner
::
ScanFlowEnd
()
void
Scanner
::
ScanFlowEnd
()
{
{
if
(
m_flowLevel
==
0
)
if
(
InBlockContext
()
)
throw
ParserException
(
INPUT
.
mark
(),
ErrorMsg
::
FLOW_END
);
throw
ParserException
(
INPUT
.
mark
(),
ErrorMsg
::
FLOW_END
);
InvalidateSimpleKey
();
// we might have a solo entry in the flow context
m_flowLevel
--
;
if
(
VerifySimpleKey
())
m_tokens
.
push
(
Token
(
Token
::
VALUE
,
INPUT
.
mark
()));
m_simpleKeyAllowed
=
false
;
m_simpleKeyAllowed
=
false
;
// eat
// eat
Mark
mark
=
INPUT
.
mark
();
Mark
mark
=
INPUT
.
mark
();
char
ch
=
INPUT
.
get
();
char
ch
=
INPUT
.
get
();
Token
::
TYPE
type
=
(
ch
==
Keys
::
FlowSeqEnd
?
Token
::
FLOW_SEQ_END
:
Token
::
FLOW_MAP_END
);
// check that it matches the start
FLOW_MARKER
flowType
=
(
ch
==
Keys
::
FlowSeqEnd
?
FLOW_SEQ
:
FLOW_MAP
);
if
(
m_flows
.
top
()
!=
flowType
)
throw
ParserException
(
mark
,
ErrorMsg
::
FLOW_END
);
m_flows
.
pop
();
Token
::
TYPE
type
=
(
flowType
?
Token
::
FLOW_SEQ_END
:
Token
::
FLOW_MAP_END
);
m_tokens
.
push
(
Token
(
type
,
mark
));
m_tokens
.
push
(
Token
(
type
,
mark
));
}
}
// FlowEntry
// FlowEntry
void
Scanner
::
ScanFlowEntry
()
void
Scanner
::
ScanFlowEntry
()
{
{
// we might have a solo entry in the flow context
if
(
VerifySimpleKey
())
m_tokens
.
push
(
Token
(
Token
::
VALUE
,
INPUT
.
mark
()));
m_simpleKeyAllowed
=
true
;
m_simpleKeyAllowed
=
true
;
// eat
// eat
...
@@ -129,7 +143,7 @@ namespace YAML
...
@@ -129,7 +143,7 @@ namespace YAML
void
Scanner
::
ScanBlockEntry
()
void
Scanner
::
ScanBlockEntry
()
{
{
// we better be in the block context!
// we better be in the block context!
if
(
m_flowLevel
>
0
)
if
(
InFlowContext
()
)
throw
ParserException
(
INPUT
.
mark
(),
ErrorMsg
::
BLOCK_ENTRY
);
throw
ParserException
(
INPUT
.
mark
(),
ErrorMsg
::
BLOCK_ENTRY
);
// can we put it here?
// can we put it here?
...
@@ -149,7 +163,7 @@ namespace YAML
...
@@ -149,7 +163,7 @@ namespace YAML
void
Scanner
::
ScanKey
()
void
Scanner
::
ScanKey
()
{
{
// handle keys diffently in the block context (and manage indents)
// handle keys diffently in the block context (and manage indents)
if
(
m_flowLevel
==
0
)
{
if
(
InBlockContext
()
)
{
if
(
!
m_simpleKeyAllowed
)
if
(
!
m_simpleKeyAllowed
)
throw
ParserException
(
INPUT
.
mark
(),
ErrorMsg
::
MAP_KEY
);
throw
ParserException
(
INPUT
.
mark
(),
ErrorMsg
::
MAP_KEY
);
...
@@ -157,10 +171,7 @@ namespace YAML
...
@@ -157,10 +171,7 @@ namespace YAML
}
}
// can only put a simple key here if we're in block context
// can only put a simple key here if we're in block context
if
(
m_flowLevel
==
0
)
m_simpleKeyAllowed
=
InBlockContext
();
m_simpleKeyAllowed
=
true
;
else
m_simpleKeyAllowed
=
false
;
// eat
// eat
Mark
mark
=
INPUT
.
mark
();
Mark
mark
=
INPUT
.
mark
();
...
@@ -182,7 +193,7 @@ namespace YAML
...
@@ -182,7 +193,7 @@ namespace YAML
m_simpleKeyAllowed
=
false
;
m_simpleKeyAllowed
=
false
;
}
else
{
}
else
{
// handle values diffently in the block context (and manage indents)
// handle values diffently in the block context (and manage indents)
if
(
m_flowLevel
==
0
)
{
if
(
InBlockContext
()
)
{
if
(
!
m_simpleKeyAllowed
)
if
(
!
m_simpleKeyAllowed
)
throw
ParserException
(
INPUT
.
mark
(),
ErrorMsg
::
MAP_VALUE
);
throw
ParserException
(
INPUT
.
mark
(),
ErrorMsg
::
MAP_VALUE
);
...
@@ -190,7 +201,7 @@ namespace YAML
...
@@ -190,7 +201,7 @@ namespace YAML
}
}
// can only put a simple key here if we're in block context
// can only put a simple key here if we're in block context
m_simpleKeyAllowed
=
(
m_flowLevel
==
0
);
m_simpleKeyAllowed
=
InBlockContext
(
);
}
}
// eat
// eat
...
@@ -206,8 +217,7 @@ namespace YAML
...
@@ -206,8 +217,7 @@ namespace YAML
std
::
string
name
;
std
::
string
name
;
// insert a potential simple key
// insert a potential simple key
if
(
m_simpleKeyAllowed
)
InsertPotentialSimpleKey
();
InsertPotentialSimpleKey
();
m_simpleKeyAllowed
=
false
;
m_simpleKeyAllowed
=
false
;
// eat the indicator
// eat the indicator
...
@@ -239,8 +249,7 @@ namespace YAML
...
@@ -239,8 +249,7 @@ namespace YAML
std
::
string
handle
,
suffix
;
std
::
string
handle
,
suffix
;
// insert a potential simple key
// insert a potential simple key
if
(
m_simpleKeyAllowed
)
InsertPotentialSimpleKey
();
InsertPotentialSimpleKey
();
m_simpleKeyAllowed
=
false
;
m_simpleKeyAllowed
=
false
;
// eat the indicator
// eat the indicator
...
@@ -278,9 +287,9 @@ namespace YAML
...
@@ -278,9 +287,9 @@ namespace YAML
// set up the scanning parameters
// set up the scanning parameters
ScanScalarParams
params
;
ScanScalarParams
params
;
params
.
end
=
(
m_flowLevel
>
0
?
Exp
::
EndScalarInFlow
:
Exp
::
EndScalar
)
||
(
Exp
::
BlankOrBreak
+
Exp
::
Comment
);
params
.
end
=
(
InFlowContext
()
?
Exp
::
EndScalarInFlow
:
Exp
::
EndScalar
)
||
(
Exp
::
BlankOrBreak
+
Exp
::
Comment
);
params
.
eatEnd
=
false
;
params
.
eatEnd
=
false
;
params
.
indent
=
(
m_flowLevel
>
0
?
0
:
GetTopIndent
()
+
1
);
params
.
indent
=
(
InFlowContext
()
?
0
:
GetTopIndent
()
+
1
);
params
.
fold
=
true
;
params
.
fold
=
true
;
params
.
eatLeadingWhitespace
=
true
;
params
.
eatLeadingWhitespace
=
true
;
params
.
trimTrailingSpaces
=
true
;
params
.
trimTrailingSpaces
=
true
;
...
@@ -289,8 +298,7 @@ namespace YAML
...
@@ -289,8 +298,7 @@ namespace YAML
params
.
onTabInIndentation
=
THROW
;
params
.
onTabInIndentation
=
THROW
;
// insert a potential simple key
// insert a potential simple key
if
(
m_simpleKeyAllowed
)
InsertPotentialSimpleKey
();
InsertPotentialSimpleKey
();
Mark
mark
=
INPUT
.
mark
();
Mark
mark
=
INPUT
.
mark
();
scalar
=
ScanScalar
(
INPUT
,
params
);
scalar
=
ScanScalar
(
INPUT
,
params
);
...
@@ -329,8 +337,7 @@ namespace YAML
...
@@ -329,8 +337,7 @@ namespace YAML
params
.
onDocIndicator
=
THROW
;
params
.
onDocIndicator
=
THROW
;
// insert a potential simple key
// insert a potential simple key
if
(
m_simpleKeyAllowed
)
InsertPotentialSimpleKey
();
InsertPotentialSimpleKey
();
Mark
mark
=
INPUT
.
mark
();
Mark
mark
=
INPUT
.
mark
();
...
...
src/simplekey.cpp
View file @
91163d22
...
@@ -31,6 +31,18 @@ namespace YAML
...
@@ -31,6 +31,18 @@ namespace YAML
if
(
pKey
)
if
(
pKey
)
pKey
->
status
=
Token
::
INVALID
;
pKey
->
status
=
Token
::
INVALID
;
}
}
// CanInsertPotentialSimpleKey
bool
Scanner
::
CanInsertPotentialSimpleKey
()
const
{
if
(
!
m_simpleKeyAllowed
)
return
false
;
if
(
InFlowContext
()
&&
m_flows
.
top
()
!=
FLOW_MAP
)
return
false
;
return
!
ExistsActiveSimpleKey
();
}
// ExistsActiveSimpleKey
// ExistsActiveSimpleKey
// . Returns true if there's a potential simple key at our flow level
// . Returns true if there's a potential simple key at our flow level
...
@@ -41,7 +53,7 @@ namespace YAML
...
@@ -41,7 +53,7 @@ namespace YAML
return
false
;
return
false
;
const
SimpleKey
&
key
=
m_simpleKeys
.
top
();
const
SimpleKey
&
key
=
m_simpleKeys
.
top
();
return
key
.
flowLevel
==
m_f
lowLevel
;
return
key
.
flowLevel
==
GetF
lowLevel
()
;
}
}
// InsertPotentialSimpleKey
// InsertPotentialSimpleKey
...
@@ -49,10 +61,10 @@ namespace YAML
...
@@ -49,10 +61,10 @@ namespace YAML
// and save it on a stack.
// and save it on a stack.
void
Scanner
::
InsertPotentialSimpleKey
()
void
Scanner
::
InsertPotentialSimpleKey
()
{
{
if
(
ExistsActive
SimpleKey
())
if
(
!
CanInsertPotential
SimpleKey
())
return
;
return
;
SimpleKey
key
(
INPUT
.
mark
(),
m_f
lowLevel
);
SimpleKey
key
(
INPUT
.
mark
(),
GetF
lowLevel
()
);
// first add a map start, if necessary
// first add a map start, if necessary
key
.
pIndent
=
PushIndentTo
(
INPUT
.
column
(),
IndentMarker
::
MAP
);
key
.
pIndent
=
PushIndentTo
(
INPUT
.
column
(),
IndentMarker
::
MAP
);
...
@@ -79,7 +91,7 @@ namespace YAML
...
@@ -79,7 +91,7 @@ namespace YAML
// grab top key
// grab top key
SimpleKey
&
key
=
m_simpleKeys
.
top
();
SimpleKey
&
key
=
m_simpleKeys
.
top
();
if
(
key
.
flowLevel
!=
m_f
lowLevel
)
if
(
key
.
flowLevel
!=
GetF
lowLevel
()
)
return
;
return
;
key
.
Invalidate
();
key
.
Invalidate
();
...
@@ -91,28 +103,21 @@ namespace YAML
...
@@ -91,28 +103,21 @@ namespace YAML
// and if so, makes it valid.
// and if so, makes it valid.
bool
Scanner
::
VerifySimpleKey
()
bool
Scanner
::
VerifySimpleKey
()
{
{
m_isLastKeyValid
=
false
;
if
(
m_simpleKeys
.
empty
())
if
(
m_simpleKeys
.
empty
())
return
m_isLastKeyValid
;
return
false
;
// grab top key
// grab top key
SimpleKey
key
=
m_simpleKeys
.
top
();
SimpleKey
key
=
m_simpleKeys
.
top
();
// only validate if we're in the correct flow level
// only validate if we're in the correct flow level
if
(
key
.
flowLevel
!=
m_f
lowLevel
)
if
(
key
.
flowLevel
!=
GetF
lowLevel
()
)
return
false
;
return
false
;
m_simpleKeys
.
pop
();
m_simpleKeys
.
pop
();
bool
isValid
=
true
;
bool
isValid
=
true
;
// needs to be followed immediately by a value
// needs to be less than 1024 characters and inline
if
(
m_flowLevel
>
0
&&
!
Exp
::
ValueInFlow
.
Matches
(
INPUT
))
isValid
=
false
;
if
(
m_flowLevel
==
0
&&
!
Exp
::
Value
.
Matches
(
INPUT
))
isValid
=
false
;
// also needs to be less than 1024 characters and inline
if
(
INPUT
.
line
()
!=
key
.
mark
.
line
||
INPUT
.
pos
()
-
key
.
mark
.
pos
>
1024
)
if
(
INPUT
.
line
()
!=
key
.
mark
.
line
||
INPUT
.
pos
()
-
key
.
mark
.
pos
>
1024
)
isValid
=
false
;
isValid
=
false
;
...
@@ -122,7 +127,6 @@ namespace YAML
...
@@ -122,7 +127,6 @@ namespace YAML
else
else
key
.
Invalidate
();
key
.
Invalidate
();
m_isLastKeyValid
=
isValid
;
return
isValid
;
return
isValid
;
}
}
...
...
yaml-reader/parsertests.cpp
View file @
91163d22
...
@@ -235,7 +235,7 @@ namespace Test
...
@@ -235,7 +235,7 @@ namespace Test
return
true
;
return
true
;
}
}
bool
FlowMapWithOmittedValue
()
bool
FlowMapWithOmittedValue
()
{
{
std
::
string
input
=
"{a: b, c:, d:}"
;
std
::
string
input
=
"{a: b, c:, d:}"
;
...
@@ -256,6 +256,45 @@ namespace Test
...
@@ -256,6 +256,45 @@ namespace Test
return
true
;
return
true
;
}
}
bool
FlowMapWithSoloEntry
()
{
std
::
string
input
=
"{a: b, c, d: e}"
;
std
::
stringstream
stream
(
input
);
YAML
::
Parser
parser
(
stream
);
YAML
::
Node
doc
;
parser
.
GetNextDocument
(
doc
);
std
::
string
output
;
doc
[
"a"
]
>>
output
;
if
(
output
!=
"b"
)
return
false
;
if
(
!
IsNull
(
doc
[
"c"
]))
return
false
;
doc
[
"d"
]
>>
output
;
if
(
output
!=
"e"
)
return
false
;
return
true
;
}
bool
FlowMapEndingWithSoloEntry
()
{
std
::
string
input
=
"{a: b, c}"
;
std
::
stringstream
stream
(
input
);
YAML
::
Parser
parser
(
stream
);
YAML
::
Node
doc
;
parser
.
GetNextDocument
(
doc
);
std
::
string
output
;
doc
[
"a"
]
>>
output
;
if
(
output
!=
"b"
)
return
false
;
if
(
!
IsNull
(
doc
[
"c"
]))
return
false
;
return
true
;
}
bool
QuotedSimpleKeys
()
bool
QuotedSimpleKeys
()
{
{
std
::
string
KeyValue
[
3
]
=
{
"
\"
double
\"
: double
\n
"
,
"'single': single
\n
"
,
"plain: plain
\n
"
};
std
::
string
KeyValue
[
3
]
=
{
"
\"
double
\"
: double
\n
"
,
"'single': single
\n
"
,
"plain: plain
\n
"
};
...
...
yaml-reader/tests.cpp
View file @
91163d22
...
@@ -268,6 +268,8 @@ namespace Test
...
@@ -268,6 +268,8 @@ namespace Test
RunParserTest
(
&
Parser
::
FlowMap
,
"flow map"
,
passed
);
RunParserTest
(
&
Parser
::
FlowMap
,
"flow map"
,
passed
);
RunParserTest
(
&
Parser
::
FlowMapWithOmittedKey
,
"flow map with omitted key"
,
passed
);
RunParserTest
(
&
Parser
::
FlowMapWithOmittedKey
,
"flow map with omitted key"
,
passed
);
RunParserTest
(
&
Parser
::
FlowMapWithOmittedValue
,
"flow map with omitted value"
,
passed
);
RunParserTest
(
&
Parser
::
FlowMapWithOmittedValue
,
"flow map with omitted value"
,
passed
);
RunParserTest
(
&
Parser
::
FlowMapWithSoloEntry
,
"flow map with solo entry"
,
passed
);
RunParserTest
(
&
Parser
::
FlowMapEndingWithSoloEntry
,
"flow map ending with solo entry"
,
passed
);
RunParserTest
(
&
Parser
::
QuotedSimpleKeys
,
"quoted simple keys"
,
passed
);
RunParserTest
(
&
Parser
::
QuotedSimpleKeys
,
"quoted simple keys"
,
passed
);
RunParserTest
(
&
Parser
::
CompressedMapAndSeq
,
"compressed map and seq"
,
passed
);
RunParserTest
(
&
Parser
::
CompressedMapAndSeq
,
"compressed map and seq"
,
passed
);
RunParserTest
(
&
Parser
::
NullBlockSeqEntry
,
"null block seq entry"
,
passed
);
RunParserTest
(
&
Parser
::
NullBlockSeqEntry
,
"null block seq entry"
,
passed
);
...
...
yaml-reader/tests.h
View file @
91163d22
...
@@ -35,6 +35,8 @@ namespace Test {
...
@@ -35,6 +35,8 @@ namespace Test {
bool
FlowMap
();
bool
FlowMap
();
bool
FlowMapWithOmittedKey
();
bool
FlowMapWithOmittedKey
();
bool
FlowMapWithOmittedValue
();
bool
FlowMapWithOmittedValue
();
bool
FlowMapWithSoloEntry
();
bool
FlowMapEndingWithSoloEntry
();
bool
QuotedSimpleKeys
();
bool
QuotedSimpleKeys
();
bool
CompressedMapAndSeq
();
bool
CompressedMapAndSeq
();
bool
NullBlockSeqEntry
();
bool
NullBlockSeqEntry
();
...
...
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