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
b95aa146
Commit
b95aa146
authored
Jul 17, 2024
by
Simon Gene Gottlieb
Committed by
Jesse Beder
Jul 17, 2024
Browse files
fix: use C locale by default
parent
1d8ca1f3
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
19 additions
and
0 deletions
+19
-0
include/yaml-cpp/emitter.h
include/yaml-cpp/emitter.h
+2
-0
include/yaml-cpp/node/convert.h
include/yaml-cpp/node/convert.h
+2
-0
include/yaml-cpp/traits.h
include/yaml-cpp/traits.h
+1
-0
src/node_data.cpp
src/node_data.cpp
+1
-0
src/parser.cpp
src/parser.cpp
+1
-0
test/node/node_test.cpp
test/node/node_test.cpp
+12
-0
No files found.
include/yaml-cpp/emitter.h
View file @
b95aa146
...
@@ -141,6 +141,7 @@ inline Emitter& Emitter::WriteIntegralType(T value) {
...
@@ -141,6 +141,7 @@ inline Emitter& Emitter::WriteIntegralType(T value) {
PrepareNode
(
EmitterNodeType
::
Scalar
);
PrepareNode
(
EmitterNodeType
::
Scalar
);
std
::
stringstream
stream
;
std
::
stringstream
stream
;
stream
.
imbue
(
std
::
locale
(
"C"
));
PrepareIntegralStream
(
stream
);
PrepareIntegralStream
(
stream
);
stream
<<
value
;
stream
<<
value
;
m_stream
<<
stream
.
str
();
m_stream
<<
stream
.
str
();
...
@@ -158,6 +159,7 @@ inline Emitter& Emitter::WriteStreamable(T value) {
...
@@ -158,6 +159,7 @@ inline Emitter& Emitter::WriteStreamable(T value) {
PrepareNode
(
EmitterNodeType
::
Scalar
);
PrepareNode
(
EmitterNodeType
::
Scalar
);
std
::
stringstream
stream
;
std
::
stringstream
stream
;
stream
.
imbue
(
std
::
locale
(
"C"
));
SetStreamablePrecision
<
T
>
(
stream
);
SetStreamablePrecision
<
T
>
(
stream
);
bool
special
=
false
;
bool
special
=
false
;
...
...
include/yaml-cpp/node/convert.h
View file @
b95aa146
...
@@ -171,6 +171,7 @@ ConvertStreamTo(std::stringstream& stream, T& rhs) {
...
@@ -171,6 +171,7 @@ ConvertStreamTo(std::stringstream& stream, T& rhs) {
\
\
static Node encode(const type& rhs) { \
static Node encode(const type& rhs) { \
std::stringstream stream; \
std::stringstream stream; \
stream.imbue(std::locale("C")); \
stream.precision(std::numeric_limits<type>::max_digits10); \
stream.precision(std::numeric_limits<type>::max_digits10); \
conversion::inner_encode(rhs, stream); \
conversion::inner_encode(rhs, stream); \
return Node(stream.str()); \
return Node(stream.str()); \
...
@@ -182,6 +183,7 @@ ConvertStreamTo(std::stringstream& stream, T& rhs) {
...
@@ -182,6 +183,7 @@ ConvertStreamTo(std::stringstream& stream, T& rhs) {
} \
} \
const std::string& input = node.Scalar(); \
const std::string& input = node.Scalar(); \
std::stringstream stream(input); \
std::stringstream stream(input); \
stream.imbue(std::locale("C")); \
stream.unsetf(std::ios::dec); \
stream.unsetf(std::ios::dec); \
if ((stream.peek() == '-') && std::is_unsigned<type>::value) { \
if ((stream.peek() == '-') && std::is_unsigned<type>::value) { \
return false; \
return false; \
...
...
include/yaml-cpp/traits.h
View file @
b95aa146
...
@@ -121,6 +121,7 @@ template<typename Key, bool Streamable>
...
@@ -121,6 +121,7 @@ template<typename Key, bool Streamable>
struct
streamable_to_string
{
struct
streamable_to_string
{
static
std
::
string
impl
(
const
Key
&
key
)
{
static
std
::
string
impl
(
const
Key
&
key
)
{
std
::
stringstream
ss
;
std
::
stringstream
ss
;
ss
.
imbue
(
std
::
locale
(
"C"
));
ss
<<
key
;
ss
<<
key
;
return
ss
.
str
();
return
ss
.
str
();
}
}
...
...
src/node_data.cpp
View file @
b95aa146
...
@@ -310,6 +310,7 @@ void node_data::convert_sequence_to_map(const shared_memory_holder& pMemory) {
...
@@ -310,6 +310,7 @@ void node_data::convert_sequence_to_map(const shared_memory_holder& pMemory) {
reset_map
();
reset_map
();
for
(
std
::
size_t
i
=
0
;
i
<
m_sequence
.
size
();
i
++
)
{
for
(
std
::
size_t
i
=
0
;
i
<
m_sequence
.
size
();
i
++
)
{
std
::
stringstream
stream
;
std
::
stringstream
stream
;
stream
.
imbue
(
std
::
locale
(
"C"
));
stream
<<
i
;
stream
<<
i
;
node
&
key
=
pMemory
->
create_node
();
node
&
key
=
pMemory
->
create_node
();
...
...
src/parser.cpp
View file @
b95aa146
...
@@ -77,6 +77,7 @@ void Parser::HandleYamlDirective(const Token& token) {
...
@@ -77,6 +77,7 @@ void Parser::HandleYamlDirective(const Token& token) {
}
}
std
::
stringstream
str
(
token
.
params
[
0
]);
std
::
stringstream
str
(
token
.
params
[
0
]);
str
.
imbue
(
std
::
locale
(
"C"
));
str
>>
m_pDirectives
->
version
.
major
;
str
>>
m_pDirectives
->
version
.
major
;
str
.
get
();
str
.
get
();
str
>>
m_pDirectives
->
version
.
minor
;
str
>>
m_pDirectives
->
version
.
minor
;
...
...
test/node/node_test.cpp
View file @
b95aa146
...
@@ -849,5 +849,17 @@ TEST_F(NodeEmitterTest, NestFlowMapListNode) {
...
@@ -849,5 +849,17 @@ TEST_F(NodeEmitterTest, NestFlowMapListNode) {
ExpectOutput
(
"{position: [1.5, 2.25, 3.125]}"
,
mapNode
);
ExpectOutput
(
"{position: [1.5, 2.25, 3.125]}"
,
mapNode
);
}
}
TEST_F
(
NodeEmitterTest
,
RobustAgainstLocale
)
{
std
::
locale
::
global
(
std
::
locale
(
""
));
Node
node
;
node
.
push_back
(
1.5
);
node
.
push_back
(
2.25
);
node
.
push_back
(
3.125
);
node
.
push_back
(
123456789
);
ExpectOutput
(
"- 1.5
\n
- 2.25
\n
- 3.125
\n
- 123456789"
,
node
);
}
}
}
}
}
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