Skip to content

Commit 6829f58

Browse files
committed
Remove USE_LOCALE, no longer necessary with C++20
1 parent 23cc690 commit 6829f58

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ include(GNUInstallDirs)
2626
include(MaximumWarnings)
2727
include(ClangTidy)
2828

29-
option(USE_LOCALE "Use C++ locale support" OFF)
30-
31-
if(USE_LOCALE)
32-
add_definitions(-DSEXP_USE_LOCALE)
33-
endif()
34-
3529
set(CMAKE_CXX_STANDARD 20)
3630
set(CMAKE_CXX_STANDARD_REQUIRED ON)
3731
set(CMAKE_CXX_EXTENSIONS OFF)

src/value.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ std::string
2727
Value::str() const
2828
{
2929
std::ostringstream os;
30-
#ifdef SEXP_USE_LOCALE
31-
os.imbue(std::locale::classic());
32-
#endif
3330
os << *this;
3431
return os.str();
3532
}

tests/io_test.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,21 @@ TEST(IOTest, roundtrip)
3838
}
3939
}
4040

41-
#ifdef SEXP_USE_LOCALE
42-
4341
TEST(IOLocaleTest, locale_safe_output)
4442
{
4543
auto sx = sexp::Value::real(0.015625f);
4644
std::stringstream out;
47-
out.imbue(std::locale("de_DE.UTF-8"));
45+
46+
try {
47+
// This will fail when the locale is not installed on the system,
48+
// just ignore the test it in that case and let the test succeed.
49+
out.imbue(std::locale("de_DE.UTF-8"));
50+
} catch (std::exception const& err) {
51+
std::cerr << "warning: failed to setup locale: " << err.what() << std::endl;
52+
}
53+
4854
out << sx;
4955
ASSERT_EQ("0.015625", out.str());
5056
}
5157

52-
#endif
53-
5458
/* EOF */

tests/parser_test.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <gtest/gtest.h>
1818

19+
#include <iostream>
1920
#include <sstream>
2021

2122
#include "sexp/io.hpp"
@@ -192,9 +193,6 @@ TEST(ParserTest, line_numbers)
192193
ASSERT_EQ(3, sexp::list_ref(sx, 2).get_line());
193194
}
194195

195-
196-
#ifdef SEXP_USE_LOCALE
197-
198196
// C++ locale support comes in the form of ugly global state that
199197
// spreads over most string formating functions, changing locale can
200198
// break a lot of stuff.
@@ -209,7 +207,13 @@ class ParserLocaleTest : public ::testing::Test
209207

210208
virtual void SetUp() override
211209
{
212-
std::locale::global(std::locale("de_DE.UTF-8"));
210+
try {
211+
// This will fail when the locale is not installed on the system,
212+
// just ignore the test it in that case and let the test succeed.
213+
std::locale::global(std::locale("de_DE.UTF-8"));
214+
} catch (std::exception const& err) {
215+
std::cerr << "warning: failed to setup locale: " << err.what() << std::endl;
216+
}
213217
}
214218

215219
virtual void TearDown() override
@@ -230,6 +234,4 @@ TEST_F(ParserLocaleTest, locale_safe_output)
230234
ASSERT_EQ("0.015625", sx.str());
231235
}
232236

233-
#endif
234-
235237
/* EOF */

0 commit comments

Comments
 (0)