From cb6185fbc06d096871ae7139ea3c52d458ffef37 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 17 Aug 2018 11:22:56 +0200 Subject: [PATCH 1/2] Add compilation support with Newlib nano for embedded targets --- include/fmt/posix.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fmt/posix.h b/include/fmt/posix.h index 2fb01260..c5e27e05 100644 --- a/include/fmt/posix.h +++ b/include/fmt/posix.h @@ -266,7 +266,7 @@ class file { long getpagesize(); #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 #endif From 1efee57d8c15d1251943c6ae8f20964e5a7135d6 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 17 Aug 2018 11:25:48 +0200 Subject: [PATCH 2/2] 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. --- include/fmt/format-inl.h | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index b147b771..7822ac1d 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -18,7 +18,9 @@ #include #include #include // for std::ptrdiff_t +#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) #include +#endif #if defined(_WIN32) && defined(__MINGW32__) # include @@ -193,6 +195,7 @@ void report_error(FormatFunc func, int error_code, } } // namespace +#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) class locale { private: std::locale locale_; @@ -202,6 +205,21 @@ class locale { std::locale get() { return locale_; } }; +template +FMT_FUNC Char internal::thousands_sep(locale_provider *lp) { + std::locale loc = lp ? lp->locale().get() : std::locale(); + return std::use_facet>(loc).thousands_sep(); +} + +#else + +template +FMT_FUNC Char internal::thousands_sep(locale_provider *lp) { + return FMT_STATIC_THOUSANDS_SEPARATOR; +} + +#endif + FMT_FUNC size_t internal::count_code_points(u8string_view s) { const char8_t *data = s.data(); int num_code_points = 0; @@ -212,11 +230,6 @@ FMT_FUNC size_t internal::count_code_points(u8string_view s) { return num_code_points; } -template -FMT_FUNC Char internal::thousands_sep(locale_provider *lp) { - std::locale loc = lp ? lp->locale().get() : std::locale(); - return std::use_facet>(loc).thousands_sep(); -} FMT_FUNC void system_error::init( int err_code, string_view format_str, format_args args) { @@ -569,8 +582,9 @@ FMT_FUNC void vprint_rgb(rgb fd, rgb bg, string_view format, format_args args) { std::fputs(internal::data::RESET_COLOR, stdout); } #endif - +#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) FMT_FUNC locale locale_provider::locale() { return fmt::locale(); } +#endif FMT_END_NAMESPACE