From 82c3fa44399a3cdc6a7c3c2a0891eee3b5e3bad7 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Mon, 23 May 2016 22:42:49 +0300 Subject: [PATCH] Update the {fmt} library to fix the colision with C string.h header. --- cbp/Module.cbp | 3 +-- cbp/Sandbox.cbp | 1 - external/CppFormat/format.cc | 2 +- external/CppFormat/ostream.cc | 2 +- external/{Common => CppFormat}/posix.cc | 2 +- include/fmt/format.h | 34 ++++++++++++------------- include/fmt/ostream.h | 2 +- include/fmt/posix.h | 2 +- include/fmt/{stringf.h => string.h} | 2 +- include/fmt/{timef.h => time.h} | 0 source/Base/Shared.cpp | 2 +- 11 files changed, 24 insertions(+), 28 deletions(-) rename external/{Common => CppFormat}/posix.cc (99%) rename include/fmt/{stringf.h => string.h} (96%) rename include/fmt/{timef.h => time.h} (100%) diff --git a/cbp/Module.cbp b/cbp/Module.cbp index 6d86b588..e89a6017 100644 --- a/cbp/Module.cbp +++ b/cbp/Module.cbp @@ -392,7 +392,6 @@ - @@ -401,8 +400,8 @@ - + diff --git a/cbp/Sandbox.cbp b/cbp/Sandbox.cbp index df0eac9b..03159ddc 100644 --- a/cbp/Sandbox.cbp +++ b/cbp/Sandbox.cbp @@ -154,7 +154,6 @@ - diff --git a/external/CppFormat/format.cc b/external/CppFormat/format.cc index 886cb9b6..ad3a1cb0 100644 --- a/external/CppFormat/format.cc +++ b/external/CppFormat/format.cc @@ -25,7 +25,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "format.h" +#include "fmt/format.h" #include diff --git a/external/CppFormat/ostream.cc b/external/CppFormat/ostream.cc index 0ba30347..3868d384 100644 --- a/external/CppFormat/ostream.cc +++ b/external/CppFormat/ostream.cc @@ -25,7 +25,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "ostream.h" +#include "fmt/ostream.h" namespace fmt { diff --git a/external/Common/posix.cc b/external/CppFormat/posix.cc similarity index 99% rename from external/Common/posix.cc rename to external/CppFormat/posix.cc index 1ec746a4..c8f828a5 100644 --- a/external/Common/posix.cc +++ b/external/CppFormat/posix.cc @@ -30,7 +30,7 @@ # define _CRT_SECURE_NO_WARNINGS #endif -#include "posix.h" +#include "fmt/posix.h" #include #include diff --git a/include/fmt/format.h b/include/fmt/format.h index ab675f35..7cdac979 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -910,23 +910,6 @@ class ThousandsSep { } }; -// Returns the thousands separator for the current locale. -// On android the lconv structure is stubbed using an empty structure. -// The test is for the size only, not for the presense of -// thousands_sep in std::lconv, because if one would add thousands_sep -// at some point, the size of structure would be at least sizeof(char*). -template= sizeof(char*))> -struct Locale { - static fmt::StringRef thousands_sep() { return ""; } -}; - -template -struct Locale { - static fmt::StringRef thousands_sep() { - return static_cast(std::localeconv())->thousands_sep; - } -}; - // Formats a decimal unsigned integer value writing into buffer. // thousands_sep is a functor that is called after writing each char to // add a thousands separator if necessary. @@ -1135,6 +1118,21 @@ struct Not { enum { value = 0 }; }; template<> struct Not { enum { value = 1 }; }; +template struct LConvCheck { + LConvCheck(int) {} +}; + +// Returns the thousands separator for the current locale. +// We check if ``lconv`` contains ``thousands_sep`` because on Android +// ``lconv`` is stubbed as an empty struct. +template +inline StringRef thousands_sep( + LConv *lc, LConvCheck = 0) { + return lc->thousands_sep; +} + +inline fmt::StringRef thousands_sep(...) { return ""; } + // Makes an Arg object from any type. template class MakeValue : public Arg { @@ -2795,7 +2793,7 @@ void BasicWriter::write_int(T value, Spec spec) { } case 'n': { unsigned num_digits = internal::count_digits(abs_value); - fmt::StringRef sep = internal::Locale::thousands_sep(); + fmt::StringRef sep = internal::thousands_sep(std::localeconv()); unsigned size = static_cast( num_digits + sep.size() * (num_digits - 1) / 3); CharPtr p = prepare_int_buffer(size, spec, prefix, prefix_size) + 1; diff --git a/include/fmt/ostream.h b/include/fmt/ostream.h index 458d31de..5654eb1b 100644 --- a/include/fmt/ostream.h +++ b/include/fmt/ostream.h @@ -28,7 +28,7 @@ #ifndef FMT_OSTREAM_H_ #define FMT_OSTREAM_H_ -#include "format.h" +#include "fmt/format.h" #include namespace fmt { diff --git a/include/fmt/posix.h b/include/fmt/posix.h index ab6d12e8..a830f6b2 100644 --- a/include/fmt/posix.h +++ b/include/fmt/posix.h @@ -45,7 +45,7 @@ # include // for LC_NUMERIC_MASK on OS X #endif -#include "format.h" +#include "fmt/format.h" #ifndef FMT_POSIX # if defined(_WIN32) && !defined(__MINGW32__) diff --git a/include/fmt/stringf.h b/include/fmt/string.h similarity index 96% rename from include/fmt/stringf.h rename to include/fmt/string.h index 31c7e9d9..4fc1f767 100644 --- a/include/fmt/stringf.h +++ b/include/fmt/string.h @@ -10,7 +10,7 @@ #ifndef FMT_STRING_H_ #define FMT_STRING_H_ -#include "format.h" +#include "fmt/format.h" namespace fmt { diff --git a/include/fmt/timef.h b/include/fmt/time.h similarity index 100% rename from include/fmt/timef.h rename to include/fmt/time.h diff --git a/source/Base/Shared.cpp b/source/Base/Shared.cpp index 660b0e02..48c88855 100644 --- a/source/Base/Shared.cpp +++ b/source/Base/Shared.cpp @@ -15,7 +15,7 @@ #include // ------------------------------------------------------------------------------------------------ -#include +#include // ------------------------------------------------------------------------------------------------ namespace SqMod {