summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build/docker/ubuntu-bionic/Dockerfile1
-rw-r--r--build/docker/ubuntu-disco/Dockerfile1
-rw-r--r--build/docker/ubuntu-xenial/Dockerfile1
-rw-r--r--lib/cpp/src/thrift/TToString.h3
-rw-r--r--lib/cpp/test/JSONProtoTest.cpp24
-rw-r--r--lib/cpp/test/ToStringTest.cpp21
6 files changed, 27 insertions, 24 deletions
diff --git a/build/docker/ubuntu-bionic/Dockerfile b/build/docker/ubuntu-bionic/Dockerfile
index 0407a6fff..a11e9bae0 100644
--- a/build/docker/ubuntu-bionic/Dockerfile
+++ b/build/docker/ubuntu-bionic/Dockerfile
@@ -258,6 +258,7 @@ RUN apt-get install -y --no-install-recommends \
`# Locale dependencies` \
locales && \
locale-gen en_US.UTF-8 && \
+ locale-gen de_DE.UTF-8 && \
update-locale
# cppcheck-1.82 has a nasty cpp parser bug, so we're using something newer
diff --git a/build/docker/ubuntu-disco/Dockerfile b/build/docker/ubuntu-disco/Dockerfile
index a175ed555..de99574f4 100644
--- a/build/docker/ubuntu-disco/Dockerfile
+++ b/build/docker/ubuntu-disco/Dockerfile
@@ -260,6 +260,7 @@ RUN apt-get install -y --no-install-recommends \
`# Locale dependencies` \
locales && \
locale-gen en_US.UTF-8 && \
+ locale-gen de_DE.UTF-8 && \
update-locale
# cppcheck-1.82 has a nasty cpp parser bug, so we're using something newer
diff --git a/build/docker/ubuntu-xenial/Dockerfile b/build/docker/ubuntu-xenial/Dockerfile
index 1c4373e44..441b6929b 100644
--- a/build/docker/ubuntu-xenial/Dockerfile
+++ b/build/docker/ubuntu-xenial/Dockerfile
@@ -240,6 +240,7 @@ RUN apt-get install -y --no-install-recommends \
`# Locale dependencies` \
locales && \
locale-gen en_US.UTF-8 && \
+ locale-gen de_DE.UTF-8 && \
update-locale
# Clean up
diff --git a/lib/cpp/src/thrift/TToString.h b/lib/cpp/src/thrift/TToString.h
index fbeac51f7..79743fdcd 100644
--- a/lib/cpp/src/thrift/TToString.h
+++ b/lib/cpp/src/thrift/TToString.h
@@ -44,6 +44,7 @@ std::string to_string(const T& t) {
// is enabled.
inline std::string to_string(const float& t) {
std::ostringstream o;
+ o.imbue(std::locale("C"));
o.precision(static_cast<std::streamsize>(std::ceil(static_cast<double>(std::numeric_limits<float>::digits * std::log10(2.0f) + 1))));
o << t;
return o.str();
@@ -51,6 +52,7 @@ inline std::string to_string(const float& t) {
inline std::string to_string(const double& t) {
std::ostringstream o;
+ o.imbue(std::locale("C"));
o.precision(static_cast<std::streamsize>(std::ceil(static_cast<double>(std::numeric_limits<double>::digits * std::log10(2.0f) + 1))));
o << t;
return o.str();
@@ -58,6 +60,7 @@ inline std::string to_string(const double& t) {
inline std::string to_string(const long double& t) {
std::ostringstream o;
+ o.imbue(std::locale("C"));
o.precision(static_cast<std::streamsize>(std::ceil(static_cast<double>(std::numeric_limits<long double>::digits * std::log10(2.0f) + 1))));
o << t;
return o.str();
diff --git a/lib/cpp/test/JSONProtoTest.cpp b/lib/cpp/test/JSONProtoTest.cpp
index 6d1cd8cd8..082c8a28b 100644
--- a/lib/cpp/test/JSONProtoTest.cpp
+++ b/lib/cpp/test/JSONProtoTest.cpp
@@ -22,7 +22,6 @@
#include <iomanip>
#include <sstream>
#include <thrift/protocol/TJSONProtocol.h>
-#include <locale>
#include <memory>
#include <thrift/transport/TBufferTransports.h>
#include "gen-cpp/DebugProtoTest_types.h"
@@ -351,26 +350,3 @@ BOOST_AUTO_TEST_CASE(test_json_unicode_escaped_missing_hi_surrogate) {
BOOST_CHECK_THROW(ooe2.read(proto.get()),
apache::thrift::protocol::TProtocolException);
}
-
-BOOST_AUTO_TEST_CASE(test_json_locale_with_thousands_separator_comma) {
- testCaseSetup_1();
-
- const std::string expected_result(
- "{\"1\":{\"tf\":1},\"2\":{\"tf\":0},\"3\":{\"i8\":127},\"4\":{\"i16\":27000},"
- "\"5\":{\"i32\":16777216},\"6\":{\"i64\":6000000000},\"7\":{\"dbl\":3.1415926"
- "535897931},\"8\":{\"str\":\"JSON THIS! \\\"\\u0001\"},\"9\":{\"str\":\"\xd7\\"
- "n\\u0007\\t\"},\"10\":{\"tf\":0},\"11\":{\"str\":\"AQIDrQ\"},\"12\":{\"lst\""
- ":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16\",3,1,2,3]},\"14\":{\"lst\":[\"i64"
- "\",3,1,2,3]}}");
-
-#if _WIN32
- std::locale::global(std::locale("en-US.UTF-8"));
-#else
- std::locale::global(std::locale("en_US.UTF-8"));
-#endif
-
- const std::string result(apache::thrift::ThriftJSONString(*ooe));
-
- BOOST_CHECK_MESSAGE(!expected_result.compare(result),
- "Expected:\n" << expected_result << "\nGotten:\n" << result);
-}
diff --git a/lib/cpp/test/ToStringTest.cpp b/lib/cpp/test/ToStringTest.cpp
index 5a05ed70a..722e5904c 100644
--- a/lib/cpp/test/ToStringTest.cpp
+++ b/lib/cpp/test/ToStringTest.cpp
@@ -19,6 +19,7 @@
#include <vector>
#include <map>
+#include <locale>
#include <boost/test/unit_test.hpp>
@@ -40,6 +41,26 @@ BOOST_AUTO_TEST_CASE(base_types_to_string) {
BOOST_CHECK_EQUAL(to_string("abc"), "abc");
}
+BOOST_AUTO_TEST_CASE(locale_en_US_int_to_string) {
+#if _WIN32
+ std::locale::global(std::locale("en-US.UTF-8"));
+#else
+ std::locale::global(std::locale("en_US.UTF-8"));
+#endif
+ BOOST_CHECK_EQUAL(to_string(1000000), "1000000");
+}
+
+BOOST_AUTO_TEST_CASE(locale_de_DE_floating_point_to_string) {
+#if _WIN32
+ std::locale::global(std::locale("de-DE.UTF-8"));
+#else
+ std::locale::global(std::locale("de_DE.UTF-8"));
+#endif
+ BOOST_CHECK_EQUAL(to_string(1.5), "1.5");
+ BOOST_CHECK_EQUAL(to_string(1.5f), "1.5");
+ BOOST_CHECK_EQUAL(to_string(1.5L), "1.5");
+}
+
BOOST_AUTO_TEST_CASE(empty_vector_to_string) {
std::vector<int> l;
BOOST_CHECK_EQUAL(to_string(l), "[]");