From ef28ade27c9e9c478b3636d7c516f2be1080339c Mon Sep 17 00:00:00 2001 From: Toni500git Date: Tue, 7 May 2024 16:23:26 +0200 Subject: [PATCH] core: update {fmt} library + fix taur getting the terminal colunms --- include/config.hpp | 1 + include/fmt/args.h | 8 +- include/fmt/base.h | 41 +++---- include/fmt/chrono.h | 140 +++++++++++++++++------- include/fmt/compile.h | 4 +- include/fmt/format-inl.h | 10 +- include/fmt/format.h | 42 +++++--- include/fmt/os.h | 10 +- include/fmt/ostream.h | 4 +- include/fmt/printf.h | 6 +- include/fmt/ranges.h | 226 ++++++++++++++++++++++----------------- include/fmt/std.h | 57 +++++----- include/fmt/xchar.h | 18 +++- include/pacman.hpp | 5 + src/config.cpp | 3 +- src/fmt/Makefile | 3 +- src/fmt/os.cc | 2 +- src/util.cpp | 1 + 18 files changed, 364 insertions(+), 217 deletions(-) diff --git a/include/config.hpp b/include/config.hpp index 0e3a626..bbf0ad2 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -1,5 +1,6 @@ #ifndef CONFIG_HPP #define CONFIG_HPP +#define TOML_HEADER_ONLY 0 #include #include diff --git a/include/fmt/args.h b/include/fmt/args.h index b77a2d0..71c3bb9 100644 --- a/include/fmt/args.h +++ b/include/fmt/args.h @@ -8,9 +8,11 @@ #ifndef FMT_ARGS_H_ #define FMT_ARGS_H_ -#include // std::reference_wrapper -#include // std::unique_ptr -#include +#ifndef FMT_IMPORT_STD +# include // std::reference_wrapper +# include // std::unique_ptr +# include +#endif #include "format.h" // std_string_view diff --git a/include/fmt/base.h b/include/fmt/base.h index bc9cfb2..772bc02 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -12,9 +12,13 @@ #include // FILE #include // strlen +#ifndef FMT_IMPORT_STD // is also included transitively from . -#include // std::byte -#include // std::enable_if +# include // std::byte +# include // std::enable_if +#else +import std; +#endif // The fmt library version in the form major * 10000 + minor * 100 + patch. #define FMT_VERSION 100202 @@ -137,7 +141,7 @@ #elif defined(__NVCOMPILER) # define FMT_USE_NONTYPE_TEMPLATE_ARGS 0 #elif FMT_GCC_VERSION >= 903 && FMT_CPLUSPLUS >= 201709L -# define FMT_USE_NONTYPE_TEMPLATE_ARGS 0 +# define FMT_USE_NONTYPE_TEMPLATE_ARGS 1 #elif defined(__cpp_nontype_template_args) && \ __cpp_nontype_template_args >= 201911L # define FMT_USE_NONTYPE_TEMPLATE_ARGS 1 @@ -175,8 +179,7 @@ #endif // Disable [[noreturn]] on MSVC/NVCC because of bogus unreachable code warnings. -#if FMT_HAS_CPP_ATTRIBUTE(noreturn) && FMT_EXCEPTIONS && !FMT_MSC_VERSION && \ - !defined(__NVCC__) +#if FMT_HAS_CPP_ATTRIBUTE(noreturn) && !FMT_MSC_VERSION && !defined(__NVCC__) # define FMT_NORETURN [[noreturn]] #else # define FMT_NORETURN @@ -368,17 +371,17 @@ template constexpr auto const_check(T value) -> T { return value; } FMT_NORETURN FMT_API void assert_fail(const char* file, int line, const char* message); -#ifndef FMT_ASSERT -# ifdef NDEBUG +#if defined(FMT_ASSERT) +// Use the provided definition. +#elif defined(NDEBUG) // FMT_ASSERT is not empty to avoid -Wempty-body. -# define FMT_ASSERT(condition, message) \ - fmt::detail::ignore_unused((condition), (message)) -# else -# define FMT_ASSERT(condition, message) \ - ((condition) /* void() fails with -Winvalid-constexpr on clang 4.0.1 */ \ - ? (void)0 \ - : fmt::detail::assert_fail(__FILE__, __LINE__, (message))) -# endif +# define FMT_ASSERT(condition, message) \ + fmt::detail::ignore_unused((condition), (message)) +#else +# define FMT_ASSERT(condition, message) \ + ((condition) /* void() fails with -Winvalid-constexpr on clang 4.0.1 */ \ + ? (void)0 \ + : fmt::detail::assert_fail(__FILE__, __LINE__, (message))) #endif #ifdef FMT_USE_INT128 @@ -1896,7 +1899,7 @@ template class basic_format_args { if (id < max_size()) arg = args_[id]; return arg; } - if (id >= detail::max_packed_args) return arg; + if (static_cast(id) >= detail::max_packed_args) return arg; arg.type_ = type(id); if (arg.type_ == detail::type::none_type) return arg; arg.value_ = values_[id]; @@ -2754,7 +2757,9 @@ template class format_string_checker { return id >= 0 && id < num_args ? parse_funcs_[id](context_) : begin; } - FMT_CONSTEXPR void on_error(const char* message) { report_error(message); } + FMT_NORETURN FMT_CONSTEXPR void on_error(const char* message) { + report_error(message); + } }; // A base class for compile-time strings. @@ -2811,7 +2816,7 @@ template struct native_formatter { FMT_CONSTEXPR auto parse(ParseContext& ctx) -> const Char* { if (ctx.begin() == ctx.end() || *ctx.begin() == '}') return ctx.begin(); auto end = parse_format_specs(ctx.begin(), ctx.end(), specs_, ctx, TYPE); - if (TYPE == type::char_type) check_char_specs(specs_); + if (const_check(TYPE == type::char_type)) check_char_specs(specs_); return end; } diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 65e6c7e..88dd911 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -8,15 +8,17 @@ #ifndef FMT_CHRONO_H_ #define FMT_CHRONO_H_ -#include -#include -#include // std::isfinite -#include // std::memcpy -#include -#include -#include -#include -#include +#ifndef FMT_IMPORT_STD +# include +# include +# include // std::isfinite +# include // std::memcpy +# include +# include +# include +# include +# include +#endif #include "format.h" @@ -1095,9 +1097,10 @@ inline auto to_nonnegative_int(T value, Int upper) -> Int { } template ::value)> inline auto to_nonnegative_int(T value, Int upper) -> Int { - if (value < 0 || value > static_cast(upper)) + auto int_value = static_cast(value); + if (int_value < 0 || value > static_cast(upper)) FMT_THROW(format_error("invalid value")); - return static_cast(value); + return int_value; } constexpr auto pow10(std::uint32_t n) -> long long { @@ -2040,6 +2043,7 @@ using weekday = std::chrono::weekday; using day = std::chrono::day; using month = std::chrono::month; using year = std::chrono::year; +using year_month_day = std::chrono::year_month_day; #else // A fallback version of weekday. class weekday { @@ -2085,46 +2089,71 @@ class year { constexpr explicit operator int() const noexcept { return value_; } }; -class year_month_day {}; +class year_month_day { + private: + fmt::year year_; + fmt::month month_; + fmt::day day_; + + public: + year_month_day() = default; + constexpr year_month_day(const year& y, const month& m, const day& d) noexcept + : year_(y), month_(m), day_(d) {} + constexpr auto year() const noexcept -> fmt::year { return year_; } + constexpr auto month() const noexcept -> fmt::month { return month_; } + constexpr auto day() const noexcept -> fmt::day { return day_; } +}; #endif -// A rudimentary weekday formatter. -template struct formatter { +template +struct formatter : private formatter { private: - bool localized = false; + bool localized_ = false; + bool use_tm_formatter_ = false; public: FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { - auto begin = ctx.begin(), end = ctx.end(); - if (begin != end && *begin == 'L') { - ++begin; - localized = true; + auto it = ctx.begin(), end = ctx.end(); + if (it != end && *it == 'L') { + ++it; + localized_ = true; + return it; } - return begin; + use_tm_formatter_ = it != end && *it != '}'; + return use_tm_formatter_ ? formatter::parse(ctx) : it; } template auto format(weekday wd, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); time.tm_wday = static_cast(wd.c_encoding()); - detail::get_locale loc(localized, ctx.locale()); + if (use_tm_formatter_) return formatter::format(time, ctx); + detail::get_locale loc(localized_, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_abbr_weekday(); return w.out(); } }; -template struct formatter { +template +struct formatter : private formatter { + private: + bool use_tm_formatter_ = false; + + public: FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { - return ctx.begin(); + auto it = ctx.begin(), end = ctx.end(); + use_tm_formatter_ = it != end && *it != '}'; + return use_tm_formatter_ ? formatter::parse(ctx) : it; } template auto format(day d, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); time.tm_mday = static_cast(static_cast(d)); + if (use_tm_formatter_) return formatter::format(time, ctx); detail::get_locale loc(false, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_day_of_month(detail::numeric_system::standard); @@ -2132,51 +2161,90 @@ template struct formatter { } }; -template struct formatter { +template +struct formatter : private formatter { private: - bool localized = false; + bool localized_ = false; + bool use_tm_formatter_ = false; public: FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { - auto begin = ctx.begin(), end = ctx.end(); - if (begin != end && *begin == 'L') { - ++begin; - localized = true; + auto it = ctx.begin(), end = ctx.end(); + if (it != end && *it == 'L') { + ++it; + localized_ = true; + return it; } - return begin; + use_tm_formatter_ = it != end && *it != '}'; + return use_tm_formatter_ ? formatter::parse(ctx) : it; } template auto format(month m, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); - // std::chrono::month has a range of 1-12, std::tm requires 0-11 time.tm_mon = static_cast(static_cast(m)) - 1; - detail::get_locale loc(localized, ctx.locale()); + if (use_tm_formatter_) return formatter::format(time, ctx); + detail::get_locale loc(localized_, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_abbr_month(); return w.out(); } }; -template struct formatter { +template +struct formatter : private formatter { + private: + bool use_tm_formatter_ = false; + + public: FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { - return ctx.begin(); + auto it = ctx.begin(), end = ctx.end(); + use_tm_formatter_ = it != end && *it != '}'; + return use_tm_formatter_ ? formatter::parse(ctx) : it; } template auto format(year y, FormatContext& ctx) const -> decltype(ctx.out()) { auto time = std::tm(); - // std::tm::tm_year is years since 1900 time.tm_year = static_cast(y) - 1900; - detail::get_locale loc(true, ctx.locale()); + if (use_tm_formatter_) return formatter::format(time, ctx); + detail::get_locale loc(false, ctx.locale()); auto w = detail::tm_writer(loc, ctx.out(), time); w.on_year(detail::numeric_system::standard); return w.out(); } }; +template +struct formatter : private formatter { + private: + bool use_tm_formatter_ = false; + + public: + FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) + -> decltype(ctx.begin()) { + auto it = ctx.begin(), end = ctx.end(); + use_tm_formatter_ = it != end && *it != '}'; + return use_tm_formatter_ ? formatter::parse(ctx) : it; + } + + template + auto format(year_month_day val, FormatContext& ctx) const + -> decltype(ctx.out()) { + auto time = std::tm(); + time.tm_year = static_cast(val.year()) - 1900; + time.tm_mon = static_cast(static_cast(val.month())) - 1; + time.tm_mday = static_cast(static_cast(val.day())); + if (use_tm_formatter_) return formatter::format(time, ctx); + detail::get_locale loc(true, ctx.locale()); + auto w = detail::tm_writer(loc, ctx.out(), time); + w.on_iso_date(); + return w.out(); + } +}; + template struct formatter, Char> { private: diff --git a/include/fmt/compile.h b/include/fmt/compile.h index d627852..65c68a4 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -8,7 +8,9 @@ #ifndef FMT_COMPILE_H_ #define FMT_COMPILE_H_ -#include // std::back_inserter +#ifndef FMT_IMPORT_STD +# include // std::back_inserter +#endif #include "format.h" diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 5a9afd1..fca26d4 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -8,13 +8,15 @@ #ifndef FMT_FORMAT_INL_H_ #define FMT_FORMAT_INL_H_ -#include +#ifndef FMT_IMPORT_STD +# include +# include +# include +#endif #include // errno #include -#include -#include -#ifndef FMT_STATIC_THOUSANDS_SEPARATOR +#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) && !defined(FMT_IMPORT_STD) # include #endif diff --git a/include/fmt/format.h b/include/fmt/format.h index 3aaee42..95df0ad 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -38,30 +38,35 @@ # define FMT_REMOVE_TRANSITIVE_INCLUDES #endif -#include // std::signbit -#include // uint32_t -#include // std::memcpy -#include // std::initializer_list -#include // std::numeric_limits -#if defined(__GLIBCXX__) && !defined(_GLIBCXX_USE_DUAL_ABI) +#ifndef FMT_IMPORT_STD +# include // std::signbit +# include // uint32_t +# include // std::memcpy +# include // std::initializer_list +# include // std::numeric_limits +# if defined(__GLIBCXX__) && !defined(_GLIBCXX_USE_DUAL_ABI) // Workaround for pre gcc 5 libstdc++. -# include // std::allocator_traits +# include // std::allocator_traits +# endif +# include // std::runtime_error +# include // std::string +# include // std::system_error #endif -#include // std::runtime_error -#include // std::string -#include // std::system_error #include "base.h" // Checking FMT_CPLUSPLUS for warning suppression in MSVC. -#if FMT_HAS_INCLUDE() && FMT_CPLUSPLUS > 201703L +#if FMT_HAS_INCLUDE() && FMT_CPLUSPLUS > 201703L && \ + !defined(FMT_IMPORT_STD) # include // std::bit_cast #endif // libc++ supports string_view in pre-c++17. #if FMT_HAS_INCLUDE() && \ (FMT_CPLUSPLUS >= 201703L || defined(_LIBCPP_VERSION)) -# include +# ifndef FMT_IMPORT_STD +# include +# endif # define FMT_USE_STRING_VIEW #endif @@ -2690,7 +2695,7 @@ FMT_CONSTEXPR20 auto write_float(OutputIt out, const DecimalFP& f, } template constexpr auto isnan(T value) -> bool { - return !(value >= value); // std::isnan doesn't support __float128. + return value != value; // std::isnan doesn't support __float128. } template @@ -4012,11 +4017,14 @@ FMT_FORMAT_AS(unsigned short, unsigned); FMT_FORMAT_AS(long, detail::long_type); FMT_FORMAT_AS(unsigned long, detail::ulong_type); FMT_FORMAT_AS(Char*, const Char*); -FMT_FORMAT_AS(std::basic_string, basic_string_view); FMT_FORMAT_AS(std::nullptr_t, const void*); FMT_FORMAT_AS(detail::std_string_view, basic_string_view); FMT_FORMAT_AS(void*, const void*); +template +class formatter, Char> + : public formatter, Char> {}; + template struct formatter : formatter, Char> {}; @@ -4302,7 +4310,7 @@ void vformat_to(buffer& buf, basic_string_view fmt, return begin; } - void on_error(const char* message) { report_error(message); } + FMT_NORETURN void on_error(const char* message) { report_error(message); } }; detail::parse_format_string(fmt, format_handler(out, fmt, args, loc)); } @@ -4335,8 +4343,12 @@ FMT_CONSTEXPR FMT_INLINE auto native_formatter::format( ctx); return write(ctx.out(), val, specs, ctx.locale()); } + +FMT_END_EXPORT } // namespace detail +FMT_BEGIN_EXPORT + template struct formatter : detail::native_formatter -#include -#include -#include // std::system_error +#ifndef FMT_IMPORT_STD +# include +# include +# include // std::system_error +#endif #include "format.h" @@ -388,7 +390,7 @@ class file_buffer final : public buffer { public: FMT_API file_buffer(cstring_view path, const ostream_params& params); - FMT_API file_buffer(file_buffer&& other); + FMT_API file_buffer(file_buffer&& other) noexcept; FMT_API ~file_buffer(); void flush() { diff --git a/include/fmt/ostream.h b/include/fmt/ostream.h index f9ba9d7..7ab2458 100644 --- a/include/fmt/ostream.h +++ b/include/fmt/ostream.h @@ -8,7 +8,9 @@ #ifndef FMT_OSTREAM_H_ #define FMT_OSTREAM_H_ -#include // std::filebuf +#ifndef FMT_IMPORT_STD +# include // std::filebuf +#endif #ifdef _WIN32 # ifdef __GLIBCXX__ diff --git a/include/fmt/printf.h b/include/fmt/printf.h index c060952..fb57d23 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -8,8 +8,10 @@ #ifndef FMT_PRINTF_H_ #define FMT_PRINTF_H_ -#include // std::max -#include // std::numeric_limits +#ifndef FMT_IMPORT_STD +# include // std::max +# include // std::numeric_limits +#endif #include "format.h" diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index f2b0f0e..3d9bcaf 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -8,15 +8,19 @@ #ifndef FMT_RANGES_H_ #define FMT_RANGES_H_ -#include -#include -#include -#include +#ifndef FMT_IMPORT_STD +# include +# include +# include +# include +#endif #include "format.h" FMT_BEGIN_NAMESPACE +enum class range_format { disabled, map, set, sequence, string, debug_string }; + namespace detail { template class is_map { @@ -67,13 +71,13 @@ struct has_member_fn_begin_end_t().begin()), decltype(std::declval().end())>> : std::true_type {}; -// Member function overload +// Member function overloads. template auto range_begin(T&& rng) FMT_DECLTYPE_RETURN(static_cast(rng).begin()); template auto range_end(T&& rng) FMT_DECLTYPE_RETURN(static_cast(rng).end()); -// ADL overload. Only participates in overload resolution if member functions +// ADL overloads. Only participate in overload resolution if member functions // are not found. template auto range_begin(T&& rng) @@ -246,6 +250,18 @@ FMT_CONSTEXPR auto maybe_set_debug_format(Formatter& f, bool set) template FMT_CONSTEXPR void maybe_set_debug_format(Formatter&, ...) {} +template +struct range_format_kind_ + : std::integral_constant, T>::value + ? range_format::disabled + : is_map::value ? range_format::map + : is_set::value ? range_format::set + : range_format::sequence> {}; + +template +using range_format_constant = std::integral_constant; + // These are not generic lambdas for compatibility with C++11. template struct parse_empty_specs { template FMT_CONSTEXPR void operator()(Formatter& f) { @@ -390,6 +406,23 @@ struct range_formatter< detail::string_literal{}; bool is_debug = false; + template ::value)> + auto write_debug_string(Output& out, It it, Sentinel end) const -> Output { + auto buf = basic_memory_buffer(); + for (; it != end; ++it) buf.push_back(*it); + auto specs = format_specs(); + specs.type = presentation_type::debug; + return detail::write( + out, basic_string_view(buf.data(), buf.size()), specs); + } + + template ::value)> + auto write_debug_string(Output& out, It, Sentinel) const -> Output { + return out; + } + public: FMT_CONSTEXPR range_formatter() {} @@ -448,25 +481,9 @@ struct range_formatter< return underlying_.parse(ctx); } - template ::value)> - auto write_debug_string(Output& out, It it, Sentinel end) const -> Output { - auto buf = basic_memory_buffer(); - for (; it != end; ++it) buf.push_back(*it); - auto specs = format_specs(); - specs.type = presentation_type::debug; - return detail::write( - out, basic_string_view(buf.data(), buf.size()), specs); - } - template ::value)> - auto write_debug_string(Output& out, It, Sentinel) const -> Output { - return out; - } - template auto format(R&& range, FormatContext& ctx) const -> decltype(ctx.out()) { - detail::range_mapper> mapper; + auto mapper = detail::range_mapper>(); auto out = ctx.out(); auto it = detail::range_begin(range); auto end = detail::range_end(range); @@ -485,81 +502,106 @@ struct range_formatter< } }; -enum class range_format { disabled, map, set, sequence, string, debug_string }; - -namespace detail { -template -struct range_format_kind_ - : std::integral_constant, T>::value - ? range_format::disabled - : is_map::value ? range_format::map - : is_set::value ? range_format::set - : range_format::sequence> {}; - -template -struct range_default_formatter; - -template -using range_format_constant = std::integral_constant; +template +struct range_format_kind + : conditional_t< + is_range::value, detail::range_format_kind_, + std::integral_constant> {}; -template -struct range_default_formatter< - K, R, Char, - enable_if_t<(K == range_format::sequence || K == range_format::map || - K == range_format::set)>> { +template +struct formatter< + R, Char, + enable_if_t::value != + range_format::disabled && + range_format_kind::value != range_format::map> +// Workaround a bug in MSVC 2015 and earlier. +#if !FMT_MSC_VERSION || FMT_MSC_VERSION >= 1910 + , + detail::is_formattable_delayed +#endif + >::value>> { + private: using range_type = detail::maybe_const_range; - range_formatter, Char> underlying_; - - FMT_CONSTEXPR range_default_formatter() { init(range_format_constant()); } + range_formatter, Char> range_formatter_; - FMT_CONSTEXPR void init(range_format_constant) { - underlying_.set_brackets(detail::string_literal{}, - detail::string_literal{}); - } - - FMT_CONSTEXPR void init(range_format_constant) { - underlying_.set_brackets(detail::string_literal{}, - detail::string_literal{}); - underlying_.underlying().set_brackets({}, {}); - underlying_.underlying().set_separator( - detail::string_literal{}); + public: + FMT_CONSTEXPR formatter() { + if (range_format_kind::value != range_format::set) return; + range_formatter_.set_brackets(detail::string_literal{}, + detail::string_literal{}); } - FMT_CONSTEXPR void init(range_format_constant) {} - template FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { - return underlying_.parse(ctx); + return range_formatter_.parse(ctx); } template auto format(range_type& range, FormatContext& ctx) const -> decltype(ctx.out()) { - return underlying_.format(range, ctx); + return range_formatter_.format(range, ctx); } }; -} // namespace detail - -template -struct range_format_kind - : conditional_t< - is_range::value, detail::range_format_kind_, - std::integral_constant> {}; +// A map formatter. template struct formatter< R, Char, - enable_if_t::value != - range_format::disabled> -// Workaround a bug in MSVC 2015 and earlier. -#if !FMT_MSC_VERSION || FMT_MSC_VERSION >= 1910 - , - detail::is_formattable_delayed -#endif - >::value>> - : detail::range_default_formatter::value, R, - Char> { + enable_if_t::value == range_format::map>> { + private: + using map_type = detail::maybe_const_range; + using element_type = detail::uncvref_type; + + decltype(detail::tuple::get_formatters( + detail::tuple_index_sequence())) formatters_; + bool no_delimiters_ = false; + + public: + FMT_CONSTEXPR formatter() {} + + template + FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { + auto it = ctx.begin(); + auto end = ctx.end(); + if (it != end) { + if (detail::to_ascii(*it) == 'n') { + no_delimiters_ = true; + ++it; + } + if (it != end && *it != '}') { + if (*it != ':') report_error("invalid format specifier"); + ++it; + } + ctx.advance_to(it); + } + detail::for_each(formatters_, detail::parse_empty_specs{ctx}); + return it; + } + + template + auto format(map_type& map, FormatContext& ctx) const -> decltype(ctx.out()) { + auto mapper = detail::range_mapper>(); + auto out = ctx.out(); + auto it = detail::range_begin(map); + auto end = detail::range_end(map); + + basic_string_view open = detail::string_literal{}; + if (!no_delimiters_) out = detail::copy(open, out); + int i = 0; + basic_string_view sep = detail::string_literal{}; + for (; it != end; ++it) { + if (i > 0) out = detail::copy(sep, out); + ctx.advance_to(out); + detail::for_each2(formatters_, mapper.map(*it), + detail::format_tuple_element{ + 0, ctx, detail::string_literal{}}); + ++i; + } + basic_string_view close = detail::string_literal{}; + if (!no_delimiters_) out = detail::copy(close, out); + return out; + } }; template @@ -617,22 +659,6 @@ auto join(It begin, Sentinel end, string_view sep) -> join_view { return {begin, end, sep}; } -namespace detail { -// ADL helpers for fmt::join() -namespace adl { -using std::begin; -using std::end; - -template auto adlbegin(Range& r) -> decltype(begin(r)) { - return begin(r); -} - -template auto adlend(Range& r) -> decltype(end(r)) { - return end(r); -} -} // namespace adl -} // namespace detail - /** \rst Returns a view that formats `range` with elements separated by `sep`. @@ -650,10 +676,10 @@ template auto adlend(Range& r) -> decltype(end(r)) { \endrst */ template -auto join(Range&& range, string_view sep) - -> join_view { - return join(detail::adl::adlbegin(range), detail::adl::adlend(range), sep); +auto join(Range&& r, string_view sep) + -> join_view { + return {detail::range_begin(r), detail::range_end(r), sep}; } template struct tuple_join_view : detail::view { diff --git a/include/fmt/std.h b/include/fmt/std.h index 7085cae..5a5026f 100644 --- a/include/fmt/std.h +++ b/include/fmt/std.h @@ -8,17 +8,19 @@ #ifndef FMT_STD_H_ #define FMT_STD_H_ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#ifndef FMT_IMPORT_STD +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +#endif #include "format.h" #include "ostream.h" @@ -26,25 +28,28 @@ #if FMT_HAS_INCLUDE() # include #endif + +#ifndef FMT_IMPORT_STD // Checking FMT_CPLUSPLUS for warning suppression in MSVC. -#if FMT_CPLUSPLUS >= 201703L -# if FMT_HAS_INCLUDE() -# include -# endif -# if FMT_HAS_INCLUDE() -# include -# endif -# if FMT_HAS_INCLUDE() -# include +# if FMT_CPLUSPLUS >= 201703L +# if FMT_HAS_INCLUDE() +# include +# endif +# if FMT_HAS_INCLUDE() +# include +# endif +# if FMT_HAS_INCLUDE() +# include +# endif # endif -#endif -#if FMT_HAS_INCLUDE() && FMT_CPLUSPLUS > 202002L -# include -#endif +# if FMT_HAS_INCLUDE() && FMT_CPLUSPLUS > 202002L +# include +# endif -#if FMT_CPLUSPLUS > 201703L && FMT_HAS_INCLUDE() -# include +# if FMT_CPLUSPLUS > 201703L && FMT_HAS_INCLUDE() +# include +# endif #endif // GCC 4 does not support FMT_HAS_INCLUDE. diff --git a/include/fmt/xchar.h b/include/fmt/xchar.h index 61a4b54..a6bf47f 100644 --- a/include/fmt/xchar.h +++ b/include/fmt/xchar.h @@ -8,13 +8,15 @@ #ifndef FMT_XCHAR_H_ #define FMT_XCHAR_H_ -#include +#ifndef FMT_IMPORT_STD +# include +#endif #include "color.h" #include "format.h" #include "ranges.h" -#ifndef FMT_STATIC_THOUSANDS_SEPARATOR +#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) && !defined(FMT_IMPORT_STD) # include #endif @@ -139,6 +141,13 @@ auto format(wformat_string fmt, T&&... args) -> std::wstring { return vformat(fmt::wstring_view(fmt), fmt::make_wformat_args(args...)); } +template +auto format_to(OutputIt out, wformat_string fmt, T&&... args) + -> OutputIt { + return vformat_to(out, fmt::wstring_view(fmt), + fmt::make_wformat_args(args...)); +} + // Pass char_t as a default template parameter instead of using // std::basic_string> to reduce the symbol size. template , - FMT_ENABLE_IF(detail::is_output_iterator::value&& - detail::is_exotic_char::value)> + FMT_ENABLE_IF(detail::is_output_iterator::value && + !std::is_same::value && + !std::is_same::value)> inline auto format_to(OutputIt out, const S& fmt, T&&... args) -> OutputIt { return vformat_to(out, detail::to_string_view(fmt), fmt::make_format_args>(args...)); diff --git a/include/pacman.hpp b/include/pacman.hpp index 4c6b84a..8de4b1a 100644 --- a/include/pacman.hpp +++ b/include/pacman.hpp @@ -1,5 +1,6 @@ // code taken from pacman utils // putted it on a separeted file for keeping the codebase a bit more clean +// args.cpp and args.hpp has part of pacman code too #include #include @@ -7,6 +8,10 @@ #include #include +#include +#include +#include + using std::string; using std::string_view; diff --git a/src/config.cpp b/src/config.cpp index 07a29b8..26b3164 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -1,3 +1,4 @@ +#define TOML_HEADER_ONLY 0 #include "config.hpp" #include "ini.h" #include "util.hpp" @@ -87,7 +88,7 @@ void Config::initVars() { this->debug = this->getConfigValue("general.debug", true); this->colors = this->getConfigValue("general.colors", true); this->secretRecipe = this->getConfigValue("secret.recipe", false); - fmt::disable_colors = this->colors == 0; + fmt::disable_colors = (!this->colors); sanitizeStr(this->sudo); sanitizeStr(this->editorBin); diff --git a/src/fmt/Makefile b/src/fmt/Makefile index 63f306c..7e0e289 100644 --- a/src/fmt/Makefile +++ b/src/fmt/Makefile @@ -1,5 +1,6 @@ # Variables taken from {fmt} cmake build files -# cmd: cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON +# I don't wanna use cmake +# cmd: cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF CXX ?= g++ #CXX_DEFINES = -DFMT_LIB_EXPORT -Dfmt_EXPORTS diff --git a/src/fmt/os.cc b/src/fmt/os.cc index 2ba9bc8..81177b2 100644 --- a/src/fmt/os.cc +++ b/src/fmt/os.cc @@ -381,7 +381,7 @@ file_buffer::file_buffer(cstring_view path, const ostream_params& params) set(new char[params.buffer_size], params.buffer_size); } -file_buffer::file_buffer(file_buffer&& other) +file_buffer::file_buffer(file_buffer&& other) noexcept : buffer(grow, other.data(), other.size(), other.capacity()), file_(std::move(other.file_)) { other.clear(); diff --git a/src/util.cpp b/src/util.cpp index 1c91eac..0c2f5a9 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -11,6 +11,7 @@ * that they align with the longest title. Storage for strings is stack * allocated and naively truncated to TITLE_MAXLEN characters. */ +// function from pacman code for aligning colonums static void make_aligned_titles(void) { unsigned int i;