From 4fe2fb83fe77c3ebc49f56ef3a1fa24c77688d84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=BCller?= Date: Mon, 15 Sep 2025 14:09:11 +0200 Subject: [PATCH] Use std::locale::classic() instead of creating new C locales on demand. --- include/yaml-cpp/emitter.h | 4 ++-- include/yaml-cpp/node/convert.h | 4 ++-- include/yaml-cpp/traits.h | 2 +- src/fptostring.cpp | 8 ++++---- src/node_data.cpp | 2 +- src/parser.cpp | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/yaml-cpp/emitter.h b/include/yaml-cpp/emitter.h index 70413e2..67810ef 100644 --- a/include/yaml-cpp/emitter.h +++ b/include/yaml-cpp/emitter.h @@ -148,7 +148,7 @@ inline Emitter& Emitter::WriteIntegralType(T value) { PrepareNode(EmitterNodeType::Scalar); std::stringstream stream; - stream.imbue(std::locale("C")); + stream.imbue(std::locale::classic()); PrepareIntegralStream(stream); stream << value; m_stream << stream.str(); @@ -166,7 +166,7 @@ inline Emitter& Emitter::WriteStreamable(T value) { PrepareNode(EmitterNodeType::Scalar); std::stringstream stream; - stream.imbue(std::locale("C")); + stream.imbue(std::locale::classic()); SetStreamablePrecision(stream); bool special = false; diff --git a/include/yaml-cpp/node/convert.h b/include/yaml-cpp/node/convert.h index 9ccbf53..0f04ea6 100644 --- a/include/yaml-cpp/node/convert.h +++ b/include/yaml-cpp/node/convert.h @@ -172,7 +172,7 @@ ConvertStreamTo(std::stringstream& stream, T& rhs) { \ static Node encode(const type& rhs) { \ std::stringstream stream; \ - stream.imbue(std::locale("C")); \ + stream.imbue(std::locale::classic()); \ stream.precision(std::numeric_limits::max_digits10); \ conversion::inner_encode(rhs, stream); \ return Node(stream.str()); \ @@ -184,7 +184,7 @@ ConvertStreamTo(std::stringstream& stream, T& rhs) { } \ const std::string& input = node.Scalar(); \ std::stringstream stream(input); \ - stream.imbue(std::locale("C")); \ + stream.imbue(std::locale::classic()); \ stream.unsetf(std::ios::dec); \ if ((stream.peek() == '-') && std::is_unsigned::value) { \ return false; \ diff --git a/include/yaml-cpp/traits.h b/include/yaml-cpp/traits.h index 7c4cdd9..8df9393 100644 --- a/include/yaml-cpp/traits.h +++ b/include/yaml-cpp/traits.h @@ -121,7 +121,7 @@ template struct streamable_to_string { static std::string impl(const Key& key) { std::stringstream ss; - ss.imbue(std::locale("C")); + ss.imbue(std::locale::classic()); ss << key; return ss.str(); } diff --git a/src/fptostring.cpp b/src/fptostring.cpp index 0d821e8..3026cbd 100644 --- a/src/fptostring.cpp +++ b/src/fptostring.cpp @@ -85,7 +85,7 @@ std::string FpToString(T v, int precision = 0) { // dragonbox/to_decimal does not handle value 0, inf, NaN if (v == 0 || std::isinf(v) || std::isnan(v)) { std::stringstream ss; - ss.imbue(std::locale("C")); + ss.imbue(std::locale::classic()); ss << v; return ss.str(); } @@ -98,7 +98,7 @@ std::string FpToString(T v, int precision = 0) { // defensive programming, ConvertToChars arguments are invalid if (digits_ct == -1) { std::stringstream ss; - ss.imbue(std::locale("C")); + ss.imbue(std::locale::classic()); ss << v; return ss.str(); } @@ -161,7 +161,7 @@ std::string FpToString(T v, int precision = 0) { // defensive programming, ConvertToChars arguments are invalid if (exp_digits_ct == -1) { std::stringstream ss; - ss.imbue(std::locale("C")); + ss.imbue(std::locale::classic()); ss << v; return ss.str(); } @@ -226,7 +226,7 @@ std::string FpToString(double v, size_t precision) { */ std::string FpToString(long double v, size_t precision) { std::stringstream ss; - ss.imbue(std::locale("C")); + ss.imbue(std::locale::classic()); if (precision == 0) { precision = std::numeric_limits::max_digits10; } diff --git a/src/node_data.cpp b/src/node_data.cpp index 3321263..6653bc1 100644 --- a/src/node_data.cpp +++ b/src/node_data.cpp @@ -310,7 +310,7 @@ void node_data::convert_sequence_to_map(const shared_memory_holder& pMemory) { reset_map(); for (std::size_t i = 0; i < m_sequence.size(); i++) { std::stringstream stream; - stream.imbue(std::locale("C")); + stream.imbue(std::locale::classic()); stream << i; node& key = pMemory->create_node(); diff --git a/src/parser.cpp b/src/parser.cpp index 5feda35..04e1946 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -77,7 +77,7 @@ void Parser::HandleYamlDirective(const Token& token) { } std::stringstream str(token.params[0]); - str.imbue(std::locale("C")); + str.imbue(std::locale::classic()); str >> m_pDirectives->version.major; str.get(); str >> m_pDirectives->version.minor;