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
6d5cfab5
"...composable_kernel.git" did not exist on "efbcc6eddce63453df8009e5406eef2685f0a1a9"
Unverified
Commit
6d5cfab5
authored
Jul 06, 2020
by
Chen
Committed by
GitHub
Jul 06, 2020
Browse files
fix bug from issue298:Emitter stylings settings overridden by node settings. (#915)
parent
026a53fb
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
39 additions
and
0 deletions
+39
-0
include/yaml-cpp/emitter.h
include/yaml-cpp/emitter.h
+1
-0
src/emitfromevents.cpp
src/emitfromevents.cpp
+4
-0
src/emitter.cpp
src/emitter.cpp
+4
-0
src/emitterstate.cpp
src/emitterstate.cpp
+4
-0
src/emitterstate.h
src/emitterstate.h
+1
-0
test/integration/emitter_test.cpp
test/integration/emitter_test.cpp
+25
-0
No files found.
include/yaml-cpp/emitter.h
View file @
6d5cfab5
...
@@ -59,6 +59,7 @@ class YAML_CPP_API Emitter {
...
@@ -59,6 +59,7 @@ class YAML_CPP_API Emitter {
bool
SetPostCommentIndent
(
std
::
size_t
n
);
bool
SetPostCommentIndent
(
std
::
size_t
n
);
bool
SetFloatPrecision
(
std
::
size_t
n
);
bool
SetFloatPrecision
(
std
::
size_t
n
);
bool
SetDoublePrecision
(
std
::
size_t
n
);
bool
SetDoublePrecision
(
std
::
size_t
n
);
void
RestoreGlobalModifiedSettings
();
// local setters
// local setters
Emitter
&
SetLocalValue
(
EMITTER_MANIP
value
);
Emitter
&
SetLocalValue
(
EMITTER_MANIP
value
);
...
...
src/emitfromevents.cpp
View file @
6d5cfab5
...
@@ -59,6 +59,8 @@ void EmitFromEvents::OnSequenceStart(const Mark&, const std::string& tag,
...
@@ -59,6 +59,8 @@ void EmitFromEvents::OnSequenceStart(const Mark&, const std::string& tag,
default:
default:
break
;
break
;
}
}
// Restore the global settings to eliminate the override from node style
m_emitter
.
RestoreGlobalModifiedSettings
();
m_emitter
<<
BeginSeq
;
m_emitter
<<
BeginSeq
;
m_stateStack
.
push
(
State
::
WaitingForSequenceEntry
);
m_stateStack
.
push
(
State
::
WaitingForSequenceEntry
);
}
}
...
@@ -83,6 +85,8 @@ void EmitFromEvents::OnMapStart(const Mark&, const std::string& tag,
...
@@ -83,6 +85,8 @@ void EmitFromEvents::OnMapStart(const Mark&, const std::string& tag,
default:
default:
break
;
break
;
}
}
// Restore the global settings to eliminate the override from node style
m_emitter
.
RestoreGlobalModifiedSettings
();
m_emitter
<<
BeginMap
;
m_emitter
<<
BeginMap
;
m_stateStack
.
push
(
State
::
WaitingForKey
);
m_stateStack
.
push
(
State
::
WaitingForKey
);
}
}
...
...
src/emitter.cpp
View file @
6d5cfab5
...
@@ -90,6 +90,10 @@ bool Emitter::SetDoublePrecision(std::size_t n) {
...
@@ -90,6 +90,10 @@ bool Emitter::SetDoublePrecision(std::size_t n) {
return
m_pState
->
SetDoublePrecision
(
n
,
FmtScope
::
Global
);
return
m_pState
->
SetDoublePrecision
(
n
,
FmtScope
::
Global
);
}
}
void
Emitter
::
RestoreGlobalModifiedSettings
()
{
m_pState
->
RestoreGlobalModifiedSettings
();
}
// SetLocalValue
// SetLocalValue
// . Either start/end a group, or set a modifier locally
// . Either start/end a group, or set a modifier locally
Emitter
&
Emitter
::
SetLocalValue
(
EMITTER_MANIP
value
)
{
Emitter
&
Emitter
::
SetLocalValue
(
EMITTER_MANIP
value
)
{
...
...
src/emitterstate.cpp
View file @
6d5cfab5
...
@@ -222,6 +222,10 @@ std::size_t EmitterState::LastIndent() const {
...
@@ -222,6 +222,10 @@ std::size_t EmitterState::LastIndent() const {
void
EmitterState
::
ClearModifiedSettings
()
{
m_modifiedSettings
.
clear
();
}
void
EmitterState
::
ClearModifiedSettings
()
{
m_modifiedSettings
.
clear
();
}
void
EmitterState
::
RestoreGlobalModifiedSettings
()
{
m_globalModifiedSettings
.
restore
();
}
bool
EmitterState
::
SetOutputCharset
(
EMITTER_MANIP
value
,
bool
EmitterState
::
SetOutputCharset
(
EMITTER_MANIP
value
,
FmtScope
::
value
scope
)
{
FmtScope
::
value
scope
)
{
switch
(
value
)
{
switch
(
value
)
{
...
...
src/emitterstate.h
View file @
6d5cfab5
...
@@ -72,6 +72,7 @@ class EmitterState {
...
@@ -72,6 +72,7 @@ class EmitterState {
bool
HasBegunContent
()
const
{
return
m_hasAnchor
||
m_hasTag
;
}
bool
HasBegunContent
()
const
{
return
m_hasAnchor
||
m_hasTag
;
}
void
ClearModifiedSettings
();
void
ClearModifiedSettings
();
void
RestoreGlobalModifiedSettings
();
// formatters
// formatters
void
SetLocalValue
(
EMITTER_MANIP
value
);
void
SetLocalValue
(
EMITTER_MANIP
value
);
...
...
test/integration/emitter_test.cpp
View file @
6d5cfab5
...
@@ -732,6 +732,31 @@ TEST_F(EmitterTest, GlobalLongKeyOnMap) {
...
@@ -732,6 +732,31 @@ TEST_F(EmitterTest, GlobalLongKeyOnMap) {
: *value)"
);
: *value)"
);
}
}
TEST_F
(
EmitterTest
,
GlobalSettingStyleOnSeqNode
)
{
Node
n
(
Load
(
R"(foo:
- 1
- 2
- 3
bar: aa)"
));
out
.
SetSeqFormat
(
YAML
::
Flow
);
out
<<
n
;
ExpectEmit
(
R"(foo: [1, 2, 3]
bar: aa)"
);
}
TEST_F
(
EmitterTest
,
GlobalSettingStyleOnMapNode
)
{
Node
n
(
Load
(
R"(-
foo: a
bar: b
- 2
- 3)"
));
out
.
SetMapFormat
(
YAML
::
Flow
);
out
<<
n
;
ExpectEmit
(
R"(- {foo: a, bar: b}
- 2
- 3)"
);
}
TEST_F
(
EmitterTest
,
ComplexGlobalSettings
)
{
TEST_F
(
EmitterTest
,
ComplexGlobalSettings
)
{
out
<<
BeginSeq
;
out
<<
BeginSeq
;
out
<<
Block
;
out
<<
Block
;
...
...
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