Skip to content

Commit

Permalink
update fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Oct 10, 2023
1 parent a5098d5 commit 098e944
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 94 deletions.
5 changes: 2 additions & 3 deletions 3rd/fmt/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,6 @@ template <typename CodeUnit> struct codecvt_result {
CodeUnit buf[max_size];
CodeUnit* end;
};
template <typename CodeUnit>
constexpr const size_t codecvt_result<CodeUnit>::max_size;

template <typename CodeUnit>
void write_codecvt(codecvt_result<CodeUnit>& out, string_view in_buf,
Expand Down Expand Up @@ -584,8 +582,9 @@ template <typename Period> FMT_CONSTEXPR inline const char* get_units() {
if (std::is_same<Period, std::tera>::value) return "Ts";
if (std::is_same<Period, std::peta>::value) return "Ps";
if (std::is_same<Period, std::exa>::value) return "Es";
if (std::is_same<Period, std::ratio<60>>::value) return "m";
if (std::is_same<Period, std::ratio<60>>::value) return "min";
if (std::is_same<Period, std::ratio<3600>>::value) return "h";
if (std::is_same<Period, std::ratio<86400>>::value) return "d";
return nullptr;
}

Expand Down
3 changes: 2 additions & 1 deletion 3rd/fmt/fmt/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,10 @@ template <typename Char> inline void reset_color(buffer<Char>& buffer) {
buffer.append(reset_color.begin(), reset_color.end());
}

template <typename T> struct styled_arg {
template <typename T> struct styled_arg : detail::view {
const T& value;
text_style style;
styled_arg(const T& v, text_style s) : value(v), style(s) {}
};

template <typename Char>
Expand Down
45 changes: 27 additions & 18 deletions 3rd/fmt/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <type_traits>

// The fmt library version in the form major * 10000 + minor * 100 + patch.
#define FMT_VERSION 100100
#define FMT_VERSION 100101

#if defined(__clang__) && !defined(__ibmxl__)
# define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__)
Expand Down Expand Up @@ -185,18 +185,20 @@
# define FMT_END_EXPORT
#endif

#if FMT_GCC_VERSION || FMT_CLANG_VERSION
# define FMT_VISIBILITY(value) __attribute__((visibility(value)))
#else
# define FMT_VISIBILITY(value)
#endif

#if !defined(FMT_HEADER_ONLY) && defined(_WIN32)
# ifdef FMT_LIB_EXPORT
# if defined(FMT_LIB_EXPORT)
# define FMT_API __declspec(dllexport)
# elif defined(FMT_SHARED)
# define FMT_API __declspec(dllimport)
# endif
#else
# if defined(FMT_LIB_EXPORT) || defined(FMT_SHARED)
# if defined(__GNUC__) || defined(__clang__)
# define FMT_API __attribute__((visibility("default")))
# endif
# endif
#elif defined(FMT_LIB_EXPORT) || defined(FMT_SHARED)
# define FMT_API FMT_VISIBILITY("default")
#endif
#ifndef FMT_API
# define FMT_API
Expand Down Expand Up @@ -1420,9 +1422,8 @@ template <typename Context> struct arg_mapper {
FMT_ENABLE_IF(
std::is_pointer<T>::value || std::is_member_pointer<T>::value ||
std::is_function<typename std::remove_pointer<T>::type>::value ||
(std::is_convertible<const T&, const void*>::value &&
!std::is_convertible<const T&, const char_type*>::value &&
!has_formatter<T, Context>::value))>
(std::is_array<T>::value &&
!std::is_convertible<T, const char_type*>::value))>
FMT_CONSTEXPR auto map(const T&) -> unformattable_pointer {
return {};
}
Expand Down Expand Up @@ -1662,7 +1663,6 @@ template <typename Context> class basic_format_arg {
\endrst
*/
// DEPRECATED!
FMT_EXPORT
template <typename Visitor, typename Context>
FMT_CONSTEXPR FMT_INLINE auto visit_format_arg(
Visitor&& vis, const basic_format_arg<Context>& arg) -> decltype(vis(0)) {
Expand Down Expand Up @@ -2302,9 +2302,12 @@ FMT_CONSTEXPR FMT_INLINE auto parse_format_specs(
dynamic_format_specs<Char>& specs;
type arg_type;

FMT_CONSTEXPR auto operator()(pres type, int set) -> const Char* {
if (!in(arg_type, set)) throw_format_error("invalid format specifier");
specs.type = type;
FMT_CONSTEXPR auto operator()(pres pres_type, int set) -> const Char* {
if (!in(arg_type, set)) {
if (arg_type == type::none_type) return begin;
throw_format_error("invalid format specifier");
}
specs.type = pres_type;
return begin + 1;
}
} parse_presentation_type{begin, specs, arg_type};
Expand All @@ -2321,6 +2324,7 @@ FMT_CONSTEXPR FMT_INLINE auto parse_format_specs(
case '+':
case '-':
case ' ':
if (arg_type == type::none_type) return begin;
enter_state(state::sign, in(arg_type, sint_set | float_set));
switch (c) {
case '+':
Expand All @@ -2336,14 +2340,17 @@ FMT_CONSTEXPR FMT_INLINE auto parse_format_specs(
++begin;
break;
case '#':
if (arg_type == type::none_type) return begin;
enter_state(state::hash, is_arithmetic_type(arg_type));
specs.alt = true;
++begin;
break;
case '0':
enter_state(state::zero);
if (!is_arithmetic_type(arg_type))
if (!is_arithmetic_type(arg_type)) {
if (arg_type == type::none_type) return begin;
throw_format_error("format specifier requires numeric argument");
}
if (specs.align == align::none) {
// Ignore 0 if align is specified for compatibility with std::format.
specs.align = align::numeric;
Expand All @@ -2365,12 +2372,14 @@ FMT_CONSTEXPR FMT_INLINE auto parse_format_specs(
begin = parse_dynamic_spec(begin, end, specs.width, specs.width_ref, ctx);
break;
case '.':
if (arg_type == type::none_type) return begin;
enter_state(state::precision,
in(arg_type, float_set | string_set | cstring_set));
begin = parse_precision(begin, end, specs.precision, specs.precision_ref,
ctx);
break;
case 'L':
if (arg_type == type::none_type) return begin;
enter_state(state::locale, is_arithmetic_type(arg_type));
specs.localized = true;
++begin;
Expand Down Expand Up @@ -2543,8 +2552,8 @@ FMT_CONSTEXPR auto parse_format_specs(ParseContext& ctx)
decltype(arg_mapper<context>().map(std::declval<const T&>())),
typename strip_named_arg<T>::type>;
#if defined(__cpp_if_constexpr)
if constexpr (std::is_default_constructible_v<
formatter<mapped_type, char_type>>) {
if constexpr (std::is_default_constructible<
formatter<mapped_type, char_type>>::value) {
return formatter<mapped_type, char_type>().parse(ctx);
} else {
type_is_unformattable_for<T, char_type> _;
Expand Down
9 changes: 5 additions & 4 deletions 3rd/fmt/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# include <locale>
#endif

#ifdef _WIN32
#if defined(_WIN32) && !defined(FMT_WINDOWS_NO_WCHAR)
# include <io.h> // _isatty
#endif

Expand Down Expand Up @@ -1426,7 +1426,7 @@ FMT_FUNC std::string vformat(string_view fmt, format_args args) {
}

namespace detail {
#ifndef _WIN32
#if !defined(_WIN32) || defined(FMT_WINDOWS_NO_WCHAR)
FMT_FUNC bool write_console(std::FILE*, string_view) { return false; }
#else
using dword = conditional_t<sizeof(long) == 4, unsigned long, unsigned>;
Expand All @@ -1441,12 +1441,13 @@ FMT_FUNC bool write_console(std::FILE* f, string_view text) {
return WriteConsoleW(reinterpret_cast<void*>(_get_osfhandle(fd)), u16.c_str(),
static_cast<uint32_t>(u16.size()), &written, nullptr) != 0;
}
#endif

#ifdef _WIN32
// Print assuming legacy (non-Unicode) encoding.
FMT_FUNC void vprint_mojibake(std::FILE* f, string_view fmt, format_args args) {
auto buffer = memory_buffer();
detail::vformat_to(buffer, fmt,
basic_format_args<buffer_context<char>>(args));
detail::vformat_to(buffer, fmt, args);
fwrite_fully(buffer.data(), 1, buffer.size(), f);
}
#endif
Expand Down
Loading

0 comments on commit 098e944

Please sign in to comment.