Commit abde38b4 authored by Thomas Bernard's avatar Thomas Bernard Committed by Victor Zverovich

Add compilation support with Newlib nano for embedded targets

Remove the dependency on std::locale to reduce executable sizes

For embedded target the usage of locale bring a huge amount of code to the executable, just to get hold of the thousands separator. Using a static defined thousands separator makes libfmt embedded target friendly.
parent 18400503
...@@ -18,7 +18,9 @@ ...@@ -18,7 +18,9 @@
#include <cmath> #include <cmath>
#include <cstdarg> #include <cstdarg>
#include <cstddef> // for std::ptrdiff_t #include <cstddef> // for std::ptrdiff_t
#include <locale> #if !defined(FMT_STATIC_THOUSANDS_SEPARATOR)
# include <locale>
#endif
#if defined(_WIN32) && defined(__MINGW32__) #if defined(_WIN32) && defined(__MINGW32__)
# include <cstring> # include <cstring>
...@@ -193,6 +195,7 @@ void report_error(FormatFunc func, int error_code, ...@@ -193,6 +195,7 @@ void report_error(FormatFunc func, int error_code,
} }
} // namespace } // namespace
#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR)
class locale { class locale {
private: private:
std::locale locale_; std::locale locale_;
...@@ -217,6 +220,12 @@ FMT_FUNC Char internal::thousands_sep(locale_provider *lp) { ...@@ -217,6 +220,12 @@ FMT_FUNC Char internal::thousands_sep(locale_provider *lp) {
std::locale loc = lp ? lp->locale().get() : std::locale(); std::locale loc = lp ? lp->locale().get() : std::locale();
return std::use_facet<std::numpunct<Char>>(loc).thousands_sep(); return std::use_facet<std::numpunct<Char>>(loc).thousands_sep();
} }
#else
template <typename Char>
FMT_FUNC Char internal::thousands_sep(locale_provider *lp) {
return FMT_STATIC_THOUSANDS_SEPARATOR;
}
#endif
FMT_FUNC void system_error::init( FMT_FUNC void system_error::init(
int err_code, string_view format_str, format_args args) { int err_code, string_view format_str, format_args args) {
...@@ -569,8 +578,9 @@ FMT_FUNC void vprint_rgb(rgb fd, rgb bg, string_view format, format_args args) { ...@@ -569,8 +578,9 @@ FMT_FUNC void vprint_rgb(rgb fd, rgb bg, string_view format, format_args args) {
std::fputs(internal::data::RESET_COLOR, stdout); std::fputs(internal::data::RESET_COLOR, stdout);
} }
#endif #endif
#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR)
FMT_FUNC locale locale_provider::locale() { return fmt::locale(); } FMT_FUNC locale locale_provider::locale() { return fmt::locale(); }
#endif
FMT_END_NAMESPACE FMT_END_NAMESPACE
......
...@@ -266,7 +266,8 @@ class file { ...@@ -266,7 +266,8 @@ class file {
long getpagesize(); long getpagesize();
#if (defined(LC_NUMERIC_MASK) || defined(_MSC_VER)) && \ #if (defined(LC_NUMERIC_MASK) || defined(_MSC_VER)) && \
!defined(__ANDROID__) && !defined(__CYGWIN__) && !defined(__OpenBSD__) !defined(__ANDROID__) && !defined(__CYGWIN__) && !defined(__OpenBSD__) && \
!defined(__NEWLIB_H__)
# define FMT_LOCALE # define FMT_LOCALE
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment