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
33315286
Unverified
Commit
33315286
authored
Jul 16, 2020
by
Chen
Committed by
GitHub
Jul 16, 2020
Browse files
Add the support to parsing a null value as `std::string`.
Fixes #590.
parent
4571e817
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
0 deletions
+6
-0
include/yaml-cpp/node/impl.h
include/yaml-cpp/node/impl.h
+4
-0
test/integration/load_node_test.cpp
test/integration/load_node_test.cpp
+2
-0
No files found.
include/yaml-cpp/node/impl.h
View file @
33315286
...
...
@@ -110,6 +110,8 @@ struct as_if<std::string, S> {
const
Node
&
node
;
std
::
string
operator
()(
const
S
&
fallback
)
const
{
if
(
node
.
Type
()
==
NodeType
::
Null
)
return
"null"
;
if
(
node
.
Type
()
!=
NodeType
::
Scalar
)
return
fallback
;
return
node
.
Scalar
();
...
...
@@ -138,6 +140,8 @@ struct as_if<std::string, void> {
const
Node
&
node
;
std
::
string
operator
()()
const
{
if
(
node
.
Type
()
==
NodeType
::
Null
)
return
"null"
;
if
(
node
.
Type
()
!=
NodeType
::
Scalar
)
throw
TypedBadConversion
<
std
::
string
>
(
node
.
Mark
());
return
node
.
Scalar
();
...
...
test/integration/load_node_test.cpp
View file @
33315286
...
...
@@ -314,6 +314,8 @@ TEST(NodeTest, IncorrectFlow) {
TEST
(
NodeTest
,
LoadTildeAsNull
)
{
Node
node
=
Load
(
"~"
);
ASSERT_TRUE
(
node
.
IsNull
());
EXPECT_EQ
(
node
.
as
<
std
::
string
>
(),
"null"
);
EXPECT_EQ
(
node
.
as
<
std
::
string
>
(
"~"
),
"null"
);
}
TEST
(
NodeTest
,
LoadNullWithStrTag
)
{
...
...
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