Update fmt llibrary to version 9.1 (Aug 27, 2022)
This commit is contained in:
@@ -18,8 +18,7 @@ namespace fmt_flax
|
|||||||
FORCE_INLINE static void format(fmt::basic_memory_buffer<T, fmt::inline_buffer_size, std_flax::allocator<T>>& buffer, const T* format, const Args& ... args)
|
FORCE_INLINE static void format(fmt::basic_memory_buffer<T, fmt::inline_buffer_size, std_flax::allocator<T>>& buffer, const T* format, const Args& ... args)
|
||||||
{
|
{
|
||||||
typedef fmt::buffer_context<T> context;
|
typedef fmt::buffer_context<T> context;
|
||||||
fmt::format_arg_store<context, Args...> as{ args... };
|
fmt::detail::vformat_to(buffer, fmt::basic_string_view<T>(format), fmt::make_format_args<context>(args...), {});
|
||||||
fmt::internal::vformat_to(buffer, fmt::to_string_view(format), fmt::basic_format_args<context>(as));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +36,7 @@ namespace fmt_flax
|
|||||||
template<typename FormatContext> \
|
template<typename FormatContext> \
|
||||||
auto format(const type& v, FormatContext& ctx) -> decltype(ctx.out()) \
|
auto format(const type& v, FormatContext& ctx) -> decltype(ctx.out()) \
|
||||||
{ \
|
{ \
|
||||||
return format_to(ctx.out(), TEXT(formatText), ##__VA_ARGS__); \
|
return fmt::format_to(ctx.out(), basic_string_view<Char>(TEXT(formatText)), ##__VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
}; \
|
}; \
|
||||||
}
|
}
|
||||||
@@ -57,7 +56,7 @@ namespace fmt_flax
|
|||||||
auto format(const type& v, FormatContext& ctx) -> decltype(ctx.out()) \
|
auto format(const type& v, FormatContext& ctx) -> decltype(ctx.out()) \
|
||||||
{ \
|
{ \
|
||||||
const String str = v.ToString(); \
|
const String str = v.ToString(); \
|
||||||
return fmt::internal::copy(str.Get(), str.Get() + str.Length(), ctx.out()); \
|
return fmt::detail::copy_str<Char>(str.Get(), str.Get() + str.Length(), ctx.out()); \
|
||||||
} \
|
} \
|
||||||
}; \
|
}; \
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ namespace fmt
|
|||||||
{
|
{
|
||||||
int32 year, month, day;
|
int32 year, month, day;
|
||||||
v.GetDate(year, month, day);
|
v.GetDate(year, month, day);
|
||||||
return format_to(ctx.out(), TEXT("{0}-{1:0>2}-{2:0>2} {3:0>2}:{4:0>2}:{5:0>2}"), year, month, day, v.GetHour(), v.GetMinute(), v.GetSecond());
|
return fmt::format_to(ctx.out(), basic_string_view<Char>(TEXT("{0}-{1:0>2}-{2:0>2} {3:0>2}:{4:0>2}:{5:0>2}")), year, month, day, v.GetHour(), v.GetMinute(), v.GetSecond());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1239,7 +1239,7 @@ namespace fmt
|
|||||||
template<typename FormatContext>
|
template<typename FormatContext>
|
||||||
auto format(const String& v, FormatContext& ctx) -> decltype(ctx.out())
|
auto format(const String& v, FormatContext& ctx) -> decltype(ctx.out())
|
||||||
{
|
{
|
||||||
return fmt::internal::copy(v.Get(), v.Get() + v.Length(), ctx.out());
|
return fmt::detail::copy_str<Char>(v.Get(), v.Get() + v.Length(), ctx.out());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1810,7 +1810,7 @@ namespace fmt
|
|||||||
template<typename FormatContext>
|
template<typename FormatContext>
|
||||||
auto format(const StringAnsi& v, FormatContext& ctx) -> decltype(ctx.out())
|
auto format(const StringAnsi& v, FormatContext& ctx) -> decltype(ctx.out())
|
||||||
{
|
{
|
||||||
return fmt::internal::copy(v.Get(), v.Get() + v.Length(), ctx.out());
|
return fmt::detail::copy_str<char>(v.Get(), v.Get() + v.Length(), ctx.out());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -284,7 +284,7 @@ namespace fmt
|
|||||||
template<typename FormatContext>
|
template<typename FormatContext>
|
||||||
auto format(const String& v, FormatContext& ctx) -> decltype(ctx.out())
|
auto format(const String& v, FormatContext& ctx) -> decltype(ctx.out())
|
||||||
{
|
{
|
||||||
return fmt::internal::copy(v.Get(), v.Get() + v.Length(), ctx.out());
|
return fmt::detail::copy_str<Char>(v.Get(), v.Get() + v.Length(), ctx.out());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -383,7 +383,7 @@ namespace fmt
|
|||||||
template<typename FormatContext>
|
template<typename FormatContext>
|
||||||
auto format(const StringView& v, FormatContext& ctx) -> decltype(ctx.out())
|
auto format(const StringView& v, FormatContext& ctx) -> decltype(ctx.out())
|
||||||
{
|
{
|
||||||
return fmt::internal::copy(v.Get(), v.Get() + v.Length(), ctx.out());
|
return fmt::detail::copy_str<Char>(v.Get(), v.Get() + v.Length(), ctx.out());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -553,7 +553,7 @@ namespace fmt
|
|||||||
template<typename FormatContext>
|
template<typename FormatContext>
|
||||||
auto format(const StringAnsiView& v, FormatContext& ctx) -> decltype(ctx.out())
|
auto format(const StringAnsiView& v, FormatContext& ctx) -> decltype(ctx.out())
|
||||||
{
|
{
|
||||||
return fmt::internal::copy(v.Get(), v.Get() + v.Length(), ctx.out());
|
return fmt::detail::copy_str<char>(v.Get(), v.Get() + v.Length(), ctx.out());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ TEST_CASE("Localization")
|
|||||||
auto str2 = String::Format(TEXT("1: {}, 2: {}, 3: {}"), 1, 2, 3);
|
auto str2 = String::Format(TEXT("1: {}, 2: {}, 3: {}"), 1, 2, 3);
|
||||||
CHECK(str2 == TEXT("1: 1, 2: 2, 3: 3"));
|
CHECK(str2 == TEXT("1: 1, 2: 2, 3: 3"));
|
||||||
auto str3 = String::Format(TEXT("vector: {0}"), Vector3(1, 2, 3));
|
auto str3 = String::Format(TEXT("vector: {0}"), Vector3(1, 2, 3));
|
||||||
CHECK(str3 == TEXT("vector: X:1.0 Y:2.0 Z:3.0"));
|
CHECK(str3 == TEXT("vector: X:1 Y:2 Z:3"));
|
||||||
String str = TEXT("hello");
|
String str = TEXT("hello");
|
||||||
auto str4 = String::Format(TEXT("string: {0}"), str.ToString());
|
auto str4 = String::Format(TEXT("string: {0}"), str.ToString());
|
||||||
CHECK(str4 == TEXT("string: hello"));
|
CHECK(str4 == TEXT("string: hello"));
|
||||||
@@ -44,7 +44,7 @@ TEST_CASE("Localization")
|
|||||||
// Custom type formatting
|
// Custom type formatting
|
||||||
MyStruct data = { Vector2(1, 2), 10.0f };
|
MyStruct data = { Vector2(1, 2), 10.0f };
|
||||||
auto str6 = String::Format(TEXT("{0}"), data);
|
auto str6 = String::Format(TEXT("{0}"), data);
|
||||||
CHECK(str6 == TEXT("Direction:X:1.0 Y:2.0 Speed:10.0"));
|
CHECK(str6 == TEXT("Direction:X:1 Y:2 Speed:10"));
|
||||||
|
|
||||||
// Named arguments formatting
|
// Named arguments formatting
|
||||||
String text1 = String::Format(TEXT("text: {0}, {1}"), TEXT("one"), TEXT("two"));
|
String text1 = String::Format(TEXT("text: {0}, {1}"), TEXT("one"), TEXT("two"));
|
||||||
|
|||||||
3502
Source/ThirdParty/fmt/core.h
vendored
3502
Source/ThirdParty/fmt/core.h
vendored
File diff suppressed because it is too large
Load Diff
2637
Source/ThirdParty/fmt/format-inl.h
vendored
2637
Source/ThirdParty/fmt/format-inl.h
vendored
File diff suppressed because it is too large
Load Diff
174
Source/ThirdParty/fmt/format.cpp
vendored
174
Source/ThirdParty/fmt/format.cpp
vendored
@@ -8,170 +8,42 @@
|
|||||||
#include "fmt/format-inl.h"
|
#include "fmt/format-inl.h"
|
||||||
|
|
||||||
FMT_BEGIN_NAMESPACE
|
FMT_BEGIN_NAMESPACE
|
||||||
namespace internal {
|
namespace detail {
|
||||||
|
|
||||||
template <typename T>
|
template FMT_API auto dragonbox::to_decimal(float x) noexcept
|
||||||
int format_float(char* buf, std::size_t size, const char* format, int precision,
|
-> dragonbox::decimal_fp<float>;
|
||||||
T value) {
|
template FMT_API auto dragonbox::to_decimal(double x) noexcept
|
||||||
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
-> dragonbox::decimal_fp<double>;
|
||||||
if (precision > 100000)
|
|
||||||
throw std::runtime_error(
|
|
||||||
"fuzz mode - avoid large allocation inside snprintf");
|
|
||||||
#endif
|
|
||||||
// Suppress the warning about nonliteral format string.
|
|
||||||
int (*snprintf_ptr)(char*, size_t, const char*, ...) = FMT_SNPRINTF;
|
|
||||||
return precision < 0 ? snprintf_ptr(buf, size, format, value)
|
|
||||||
: snprintf_ptr(buf, size, format, precision, value);
|
|
||||||
}
|
|
||||||
struct sprintf_specs {
|
|
||||||
int precision;
|
|
||||||
char type;
|
|
||||||
bool alt : 1;
|
|
||||||
|
|
||||||
template <typename Char>
|
|
||||||
constexpr sprintf_specs(basic_format_specs<Char> specs)
|
|
||||||
: precision(specs.precision), type(specs.type), alt(specs.alt) {}
|
|
||||||
|
|
||||||
constexpr bool has_precision() const { return precision >= 0; }
|
|
||||||
};
|
|
||||||
|
|
||||||
// This is deprecated and is kept only to preserve ABI compatibility.
|
|
||||||
template <typename Double>
|
|
||||||
char* sprintf_format(Double value, internal::buffer<char>& buf,
|
|
||||||
sprintf_specs specs) {
|
|
||||||
// Buffer capacity must be non-zero, otherwise MSVC's vsnprintf_s will fail.
|
|
||||||
FMT_ASSERT(buf.capacity() != 0, "empty buffer");
|
|
||||||
|
|
||||||
// Build format string.
|
|
||||||
enum { max_format_size = 10 }; // longest format: %#-*.*Lg
|
|
||||||
char format[max_format_size];
|
|
||||||
char* format_ptr = format;
|
|
||||||
*format_ptr++ = '%';
|
|
||||||
if (specs.alt || !specs.type) *format_ptr++ = '#';
|
|
||||||
if (specs.precision >= 0) {
|
|
||||||
*format_ptr++ = '.';
|
|
||||||
*format_ptr++ = '*';
|
|
||||||
}
|
|
||||||
if (std::is_same<Double, long double>::value) *format_ptr++ = 'L';
|
|
||||||
|
|
||||||
char type = specs.type;
|
|
||||||
|
|
||||||
if (type == '%')
|
|
||||||
type = 'f';
|
|
||||||
else if (type == 0 || type == 'n')
|
|
||||||
type = 'g';
|
|
||||||
#if FMT_MSC_VER
|
|
||||||
if (type == 'F') {
|
|
||||||
// MSVC's printf doesn't support 'F'.
|
|
||||||
type = 'f';
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
*format_ptr++ = type;
|
|
||||||
*format_ptr = '\0';
|
|
||||||
|
|
||||||
// Format using snprintf.
|
|
||||||
char* start = nullptr;
|
|
||||||
char* decimal_point_pos = nullptr;
|
|
||||||
for (;;) {
|
|
||||||
std::size_t buffer_size = buf.capacity();
|
|
||||||
start = &buf[0];
|
|
||||||
int result =
|
|
||||||
format_float(start, buffer_size, format, specs.precision, value);
|
|
||||||
if (result >= 0) {
|
|
||||||
unsigned n = internal::to_unsigned(result);
|
|
||||||
if (n < buf.capacity()) {
|
|
||||||
// Find the decimal point.
|
|
||||||
auto p = buf.data(), end = p + n;
|
|
||||||
if (*p == '+' || *p == '-') ++p;
|
|
||||||
if (specs.type != 'a' && specs.type != 'A') {
|
|
||||||
while (p < end && *p >= '0' && *p <= '9') ++p;
|
|
||||||
if (p < end && *p != 'e' && *p != 'E') {
|
|
||||||
decimal_point_pos = p;
|
|
||||||
if (!specs.type) {
|
|
||||||
// Keep only one trailing zero after the decimal point.
|
|
||||||
++p;
|
|
||||||
if (*p == '0') ++p;
|
|
||||||
while (p != end && *p >= '1' && *p <= '9') ++p;
|
|
||||||
char* where = p;
|
|
||||||
while (p != end && *p == '0') ++p;
|
|
||||||
if (p == end || *p < '0' || *p > '9') {
|
|
||||||
if (p != end) std::memmove(where, p, to_unsigned(end - p));
|
|
||||||
n -= static_cast<unsigned>(p - where);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
buf.resize(n);
|
|
||||||
break; // The buffer is large enough - continue with formatting.
|
|
||||||
}
|
|
||||||
buf.reserve(n + 1);
|
|
||||||
} else {
|
|
||||||
// If result is negative we ask to increase the capacity by at least 1,
|
|
||||||
// but as std::vector, the buffer grows exponentially.
|
|
||||||
buf.reserve(buf.capacity() + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return decimal_point_pos;
|
|
||||||
}
|
|
||||||
} // namespace internal
|
|
||||||
|
|
||||||
template FMT_API char* internal::sprintf_format(double, internal::buffer<char>&,
|
|
||||||
sprintf_specs);
|
|
||||||
template FMT_API char* internal::sprintf_format(long double,
|
|
||||||
internal::buffer<char>&,
|
|
||||||
sprintf_specs);
|
|
||||||
|
|
||||||
#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
|
#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
|
||||||
template FMT_API internal::locale_ref::locale_ref(const std::locale& loc);
|
template FMT_API locale_ref::locale_ref(const std::locale& loc);
|
||||||
template FMT_API std::locale internal::locale_ref::get<std::locale>() const;
|
template FMT_API auto locale_ref::get<std::locale>() const -> std::locale;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Explicit instantiations for char.
|
// Explicit instantiations for char.
|
||||||
|
|
||||||
#if FMT_USE_LOCALE_GROUPING
|
template FMT_API auto thousands_sep_impl(locale_ref)
|
||||||
template FMT_API std::string internal::grouping_impl<char>(locale_ref);
|
-> thousands_sep_result<char>;
|
||||||
#endif
|
template FMT_API auto decimal_point_impl(locale_ref) -> char;
|
||||||
template FMT_API char internal::thousands_sep_impl(locale_ref);
|
|
||||||
template FMT_API char internal::decimal_point_impl(locale_ref);
|
|
||||||
|
|
||||||
template FMT_API void internal::buffer<char>::append(const char*, const char*);
|
template FMT_API void buffer<char>::append(const char*, const char*);
|
||||||
|
|
||||||
template FMT_API void internal::arg_map<format_context>::init(
|
// DEPRECATED!
|
||||||
const basic_format_args<format_context>& args);
|
// There is no correspondent extern template in format.h because of
|
||||||
|
// incompatibility between clang and gcc (#2377).
|
||||||
|
template FMT_API void vformat_to(buffer<char>&, string_view,
|
||||||
|
basic_format_args<FMT_BUFFER_CONTEXT(char)>,
|
||||||
|
locale_ref);
|
||||||
|
|
||||||
#if FMT_USE_STRING
|
template FMT_API int format_float(double value, int precision, float_specs specs, buffer<char>& buf);
|
||||||
template FMT_API std::string internal::vformat<char>(
|
|
||||||
string_view, basic_format_args<format_context>);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template FMT_API format_context::iterator internal::vformat_to(
|
|
||||||
internal::buffer<char>&, string_view, basic_format_args<format_context>);
|
|
||||||
|
|
||||||
template FMT_API int internal::snprintf_float(double, int,
|
|
||||||
internal::float_specs,
|
|
||||||
internal::buffer<char>&);
|
|
||||||
template FMT_API int internal::snprintf_float(long double, int,
|
|
||||||
internal::float_specs,
|
|
||||||
internal::buffer<char>&);
|
|
||||||
template FMT_API int internal::format_float(double, int, internal::float_specs,
|
|
||||||
internal::buffer<char>&);
|
|
||||||
template FMT_API int internal::format_float(long double, int,
|
|
||||||
internal::float_specs,
|
|
||||||
internal::buffer<char>&);
|
|
||||||
|
|
||||||
// Explicit instantiations for wchar_t.
|
// Explicit instantiations for wchar_t.
|
||||||
|
|
||||||
#if FMT_USE_LOCALE_GROUPING
|
template FMT_API auto thousands_sep_impl(locale_ref)
|
||||||
template FMT_API std::string internal::grouping_impl<wchar_t>(locale_ref);
|
-> thousands_sep_result<wchar_t>;
|
||||||
#endif
|
template FMT_API auto decimal_point_impl(locale_ref) -> wchar_t;
|
||||||
template FMT_API wchar_t internal::thousands_sep_impl(locale_ref);
|
|
||||||
template FMT_API wchar_t internal::decimal_point_impl(locale_ref);
|
|
||||||
|
|
||||||
template FMT_API void internal::buffer<wchar_t>::append(const wchar_t*,
|
template FMT_API void buffer<wchar_t>::append(const wchar_t*, const wchar_t*);
|
||||||
const wchar_t*);
|
|
||||||
|
|
||||||
#if FMT_USE_STRING
|
} // namespace detail
|
||||||
template FMT_API std::wstring internal::vformat<wchar_t>(
|
|
||||||
wstring_view, basic_format_args<wformat_context>);
|
|
||||||
#endif
|
|
||||||
FMT_END_NAMESPACE
|
FMT_END_NAMESPACE
|
||||||
|
|||||||
5408
Source/ThirdParty/fmt/format.h
vendored
5408
Source/ThirdParty/fmt/format.h
vendored
File diff suppressed because it is too large
Load Diff
154
Source/ThirdParty/fmt/ostream.h
vendored
154
Source/ThirdParty/fmt/ostream.h
vendored
@@ -14,73 +14,47 @@
|
|||||||
|
|
||||||
FMT_BEGIN_NAMESPACE
|
FMT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
template <typename CHar> class basic_printf_parse_context;
|
|
||||||
template <typename OutputIt, typename Char> class basic_printf_context;
|
template <typename OutputIt, typename Char> class basic_printf_context;
|
||||||
|
|
||||||
namespace internal {
|
namespace detail {
|
||||||
|
|
||||||
template <class Char> class formatbuf : public std::basic_streambuf<Char> {
|
// Checks if T has a user-defined operator<<.
|
||||||
private:
|
template <typename T, typename Char, typename Enable = void>
|
||||||
using int_type = typename std::basic_streambuf<Char>::int_type;
|
class is_streamable {
|
||||||
using traits_type = typename std::basic_streambuf<Char>::traits_type;
|
|
||||||
|
|
||||||
buffer<Char>& buffer_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
formatbuf(buffer<Char>& buf) : buffer_(buf) {}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
// The put-area is actually always empty. This makes the implementation
|
|
||||||
// simpler and has the advantage that the streambuf and the buffer are always
|
|
||||||
// in sync and sputc never writes into uninitialized memory. The obvious
|
|
||||||
// disadvantage is that each call to sputc always results in a (virtual) call
|
|
||||||
// to overflow. There is no disadvantage here for sputn since this always
|
|
||||||
// results in a call to xsputn.
|
|
||||||
|
|
||||||
int_type overflow(int_type ch = traits_type::eof()) FMT_OVERRIDE {
|
|
||||||
if (!traits_type::eq_int_type(ch, traits_type::eof()))
|
|
||||||
buffer_.push_back(static_cast<Char>(ch));
|
|
||||||
return ch;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::streamsize xsputn(const Char* s, std::streamsize count) FMT_OVERRIDE {
|
|
||||||
buffer_.append(s, s + count);
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Char> struct test_stream : std::basic_ostream<Char> {
|
|
||||||
private:
|
|
||||||
// Hide all operator<< from std::basic_ostream<Char>.
|
|
||||||
void_t<> operator<<(null<>);
|
|
||||||
void_t<> operator<<(const Char*);
|
|
||||||
|
|
||||||
template <typename T, FMT_ENABLE_IF(std::is_convertible<T, int>::value &&
|
|
||||||
!std::is_enum<T>::value)>
|
|
||||||
void_t<> operator<<(T);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Checks if T has a user-defined operator<< (e.g. not a member of
|
|
||||||
// std::ostream).
|
|
||||||
template <typename T, typename Char> class is_streamable {
|
|
||||||
private:
|
private:
|
||||||
template <typename U>
|
template <typename U>
|
||||||
static bool_constant<!std::is_same<decltype(std::declval<test_stream<Char>&>()
|
static auto test(int)
|
||||||
<< std::declval<U>()),
|
-> bool_constant<sizeof(std::declval<std::basic_ostream<Char>&>()
|
||||||
void_t<>>::value>
|
<< std::declval<U>()) != 0>;
|
||||||
test(int);
|
|
||||||
|
|
||||||
template <typename> static std::false_type test(...);
|
template <typename> static auto test(...) -> std::false_type;
|
||||||
|
|
||||||
using result = decltype(test<T>(0));
|
using result = decltype(test<T>(0));
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
is_streamable() = default;
|
||||||
|
|
||||||
static const bool value = result::value;
|
static const bool value = result::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Formatting of built-in types and arrays is intentionally disabled because
|
||||||
|
// it's handled by standard (non-ostream) formatters.
|
||||||
|
template <typename T, typename Char>
|
||||||
|
struct is_streamable<
|
||||||
|
T, Char,
|
||||||
|
enable_if_t<
|
||||||
|
std::is_arithmetic<T>::value || std::is_array<T>::value ||
|
||||||
|
std::is_pointer<T>::value || std::is_same<T, char8_type>::value ||
|
||||||
|
std::is_convertible<T, fmt::basic_string_view<Char>>::value ||
|
||||||
|
std::is_same<T, std_string_view<Char>>::value ||
|
||||||
|
(std::is_convertible<T, int>::value && !std::is_enum<T>::value)>>
|
||||||
|
: std::false_type {};
|
||||||
|
|
||||||
|
|
||||||
// Write the content of buf to os.
|
// Write the content of buf to os.
|
||||||
|
// It is a separate function rather than a part of vprint to simplify testing.
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
void write(std::basic_ostream<Char>& os, buffer<Char>& buf) {
|
void write_buffer(std::basic_ostream<Char>& os, buffer<Char>& buf) {
|
||||||
const Char* buf_data = buf.data();
|
const Char* buf_data = buf.data();
|
||||||
using unsigned_streamsize = std::make_unsigned<std::streamsize>::type;
|
using unsigned_streamsize = std::make_unsigned<std::streamsize>::type;
|
||||||
unsigned_streamsize size = buf.size();
|
unsigned_streamsize size = buf.size();
|
||||||
@@ -96,55 +70,61 @@ void write(std::basic_ostream<Char>& os, buffer<Char>& buf) {
|
|||||||
template <typename Char, typename T>
|
template <typename Char, typename T>
|
||||||
void format_value(buffer<Char>& buf, const T& value,
|
void format_value(buffer<Char>& buf, const T& value,
|
||||||
locale_ref loc = locale_ref()) {
|
locale_ref loc = locale_ref()) {
|
||||||
formatbuf<Char> format_buf(buf);
|
auto&& format_buf = formatbuf<std::basic_streambuf<Char>>(buf);
|
||||||
std::basic_ostream<Char> output(&format_buf);
|
auto&& output = std::basic_ostream<Char>(&format_buf);
|
||||||
#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR)
|
#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR)
|
||||||
if (loc) output.imbue(loc.get<std::locale>());
|
if (loc) output.imbue(loc.get<std::locale>());
|
||||||
#endif
|
#endif
|
||||||
output.exceptions(std::ios_base::failbit | std::ios_base::badbit);
|
|
||||||
output << value;
|
output << value;
|
||||||
buf.resize(buf.size());
|
output.exceptions(std::ios_base::failbit | std::ios_base::badbit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T> struct streamed_view { const T& value; };
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
// Formats an object of type T that has an overloaded ostream operator<<.
|
// Formats an object of type T that has an overloaded ostream operator<<.
|
||||||
template <typename T, typename Char>
|
template <typename Char>
|
||||||
struct fallback_formatter<T, Char, enable_if_t<is_streamable<T, Char>::value>>
|
struct basic_ostream_formatter : formatter<basic_string_view<Char>, Char> {
|
||||||
: private formatter<basic_string_view<Char>, Char> {
|
void set_debug_format() = delete;
|
||||||
auto parse(basic_format_parse_context<Char>& ctx) -> decltype(ctx.begin()) {
|
|
||||||
return formatter<basic_string_view<Char>, Char>::parse(ctx);
|
|
||||||
}
|
|
||||||
template <typename ParseCtx,
|
|
||||||
FMT_ENABLE_IF(std::is_same<
|
|
||||||
ParseCtx, basic_printf_parse_context<Char>>::value)>
|
|
||||||
auto parse(ParseCtx& ctx) -> decltype(ctx.begin()) {
|
|
||||||
return ctx.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename OutputIt>
|
template <typename T, typename OutputIt>
|
||||||
auto format(const T& value, basic_format_context<OutputIt, Char>& ctx)
|
auto format(const T& value, basic_format_context<OutputIt, Char>& ctx) const
|
||||||
-> OutputIt {
|
-> OutputIt {
|
||||||
basic_memory_buffer<Char> buffer;
|
auto buffer = basic_memory_buffer<Char>();
|
||||||
format_value(buffer, value, ctx.locale());
|
format_value(buffer, value, ctx.locale());
|
||||||
basic_string_view<Char> str(buffer.data(), buffer.size());
|
return formatter<basic_string_view<Char>, Char>::format(
|
||||||
return formatter<basic_string_view<Char>, Char>::format(str, ctx);
|
{buffer.data(), buffer.size()}, ctx);
|
||||||
}
|
|
||||||
template <typename OutputIt>
|
|
||||||
auto format(const T& value, basic_printf_context<OutputIt, Char>& ctx)
|
|
||||||
-> OutputIt {
|
|
||||||
basic_memory_buffer<Char> buffer;
|
|
||||||
format_value(buffer, value, ctx.locale());
|
|
||||||
return std::copy(buffer.begin(), buffer.end(), ctx.out());
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace internal
|
|
||||||
|
|
||||||
template <typename Char>
|
using ostream_formatter = basic_ostream_formatter<char>;
|
||||||
void vprint(std::basic_ostream<Char>& os, basic_string_view<Char> format_str,
|
|
||||||
basic_format_args<buffer_context<type_identity_t<Char>>> args) {
|
template <typename T, typename Char>
|
||||||
basic_memory_buffer<Char> buffer;
|
struct formatter<detail::streamed_view<T>, Char>
|
||||||
internal::vformat_to(buffer, format_str, args);
|
: basic_ostream_formatter<Char> {
|
||||||
internal::write(os, buffer);
|
template <typename OutputIt>
|
||||||
|
auto format(detail::streamed_view<T> view,
|
||||||
|
basic_format_context<OutputIt, Char>& ctx) const -> OutputIt {
|
||||||
|
return basic_ostream_formatter<Char>::format(view.value, ctx);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
\rst
|
||||||
|
Returns a view that formats `value` via an ostream ``operator<<``.
|
||||||
|
|
||||||
|
**Example**::
|
||||||
|
|
||||||
|
fmt::print("Current thread id: {}\n",
|
||||||
|
fmt::streamed(std::this_thread::get_id()));
|
||||||
|
\endrst
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
auto streamed(const T& value) -> detail::streamed_view<T> {
|
||||||
|
return {value};
|
||||||
}
|
}
|
||||||
|
|
||||||
FMT_END_NAMESPACE
|
FMT_END_NAMESPACE
|
||||||
|
|
||||||
#endif // FMT_OSTREAM_H_
|
#endif // FMT_OSTREAM_H_
|
||||||
|
|||||||
Reference in New Issue
Block a user