Skip to content

Commit

Permalink
core: update {fmt} library + fix taur getting the terminal colunms
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni500github committed May 7, 2024
1 parent b6c1119 commit ef28ade
Show file tree
Hide file tree
Showing 18 changed files with 364 additions and 217 deletions.
1 change: 1 addition & 0 deletions include/config.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef CONFIG_HPP
#define CONFIG_HPP
#define TOML_HEADER_ONLY 0

#include <alpm.h>
#include <map>
Expand Down
8 changes: 5 additions & 3 deletions include/fmt/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
#ifndef FMT_ARGS_H_
#define FMT_ARGS_H_

#include <functional> // std::reference_wrapper
#include <memory> // std::unique_ptr
#include <vector>
#ifndef FMT_IMPORT_STD
# include <functional> // std::reference_wrapper
# include <memory> // std::unique_ptr
# include <vector>
#endif

#include "format.h" // std_string_view

Expand Down
41 changes: 23 additions & 18 deletions include/fmt/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
#include <stdio.h> // FILE
#include <string.h> // strlen

#ifndef FMT_IMPORT_STD
// <cstddef> is also included transitively from <type_traits>.
#include <cstddef> // std::byte
#include <type_traits> // std::enable_if
# include <cstddef> // std::byte
# include <type_traits> // std::enable_if
#else
import std;
#endif

// The fmt library version in the form major * 10000 + minor * 100 + patch.
#define FMT_VERSION 100202
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -368,17 +371,17 @@ template <typename T> 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
Expand Down Expand Up @@ -1896,7 +1899,7 @@ template <typename Context> class basic_format_args {
if (id < max_size()) arg = args_[id];
return arg;
}
if (id >= detail::max_packed_args) return arg;
if (static_cast<unsigned>(id) >= detail::max_packed_args) return arg;
arg.type_ = type(id);
if (arg.type_ == detail::type::none_type) return arg;
arg.value_ = values_[id];
Expand Down Expand Up @@ -2754,7 +2757,9 @@ template <typename Char, typename... Args> 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.
Expand Down Expand Up @@ -2811,7 +2816,7 @@ template <typename T, typename Char, type TYPE> 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;
}

Expand Down
140 changes: 104 additions & 36 deletions include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@
#ifndef FMT_CHRONO_H_
#define FMT_CHRONO_H_

#include <algorithm>
#include <chrono>
#include <cmath> // std::isfinite
#include <cstring> // std::memcpy
#include <ctime>
#include <iterator>
#include <locale>
#include <ostream>
#include <type_traits>
#ifndef FMT_IMPORT_STD
# include <algorithm>
# include <chrono>
# include <cmath> // std::isfinite
# include <cstring> // std::memcpy
# include <ctime>
# include <iterator>
# include <locale>
# include <ostream>
# include <type_traits>
#endif

#include "format.h"

Expand Down Expand Up @@ -1095,9 +1097,10 @@ inline auto to_nonnegative_int(T value, Int upper) -> Int {
}
template <typename T, typename Int, FMT_ENABLE_IF(!std::is_integral<T>::value)>
inline auto to_nonnegative_int(T value, Int upper) -> Int {
if (value < 0 || value > static_cast<T>(upper))
auto int_value = static_cast<Int>(value);
if (int_value < 0 || value > static_cast<T>(upper))
FMT_THROW(format_error("invalid value"));
return static_cast<Int>(value);
return int_value;
}

constexpr auto pow10(std::uint32_t n) -> long long {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -2085,98 +2089,162 @@ 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 <typename Char> struct formatter<weekday, Char> {
template <typename Char>
struct formatter<weekday, Char> : private formatter<std::tm, Char> {
private:
bool localized = false;
bool localized_ = false;
bool use_tm_formatter_ = false;

public:
FMT_CONSTEXPR auto parse(basic_format_parse_context<Char>& 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<std::tm, Char>::parse(ctx) : it;
}

template <typename FormatContext>
auto format(weekday wd, FormatContext& ctx) const -> decltype(ctx.out()) {
auto time = std::tm();
time.tm_wday = static_cast<int>(wd.c_encoding());
detail::get_locale loc(localized, ctx.locale());
if (use_tm_formatter_) return formatter<std::tm, Char>::format(time, ctx);
detail::get_locale loc(localized_, ctx.locale());
auto w = detail::tm_writer<decltype(ctx.out()), Char>(loc, ctx.out(), time);
w.on_abbr_weekday();
return w.out();
}
};

template <typename Char> struct formatter<day, Char> {
template <typename Char>
struct formatter<day, Char> : private formatter<std::tm, Char> {
private:
bool use_tm_formatter_ = false;

public:
FMT_CONSTEXPR auto parse(basic_format_parse_context<Char>& 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<std::tm, Char>::parse(ctx) : it;
}

template <typename FormatContext>
auto format(day d, FormatContext& ctx) const -> decltype(ctx.out()) {
auto time = std::tm();
time.tm_mday = static_cast<int>(static_cast<unsigned>(d));
if (use_tm_formatter_) return formatter<std::tm, Char>::format(time, ctx);
detail::get_locale loc(false, ctx.locale());
auto w = detail::tm_writer<decltype(ctx.out()), Char>(loc, ctx.out(), time);
w.on_day_of_month(detail::numeric_system::standard);
return w.out();
}
};

template <typename Char> struct formatter<month, Char> {
template <typename Char>
struct formatter<month, Char> : private formatter<std::tm, Char> {
private:
bool localized = false;
bool localized_ = false;
bool use_tm_formatter_ = false;

public:
FMT_CONSTEXPR auto parse(basic_format_parse_context<Char>& 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<std::tm, Char>::parse(ctx) : it;
}

template <typename FormatContext>
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<int>(static_cast<unsigned>(m)) - 1;
detail::get_locale loc(localized, ctx.locale());
if (use_tm_formatter_) return formatter<std::tm, Char>::format(time, ctx);
detail::get_locale loc(localized_, ctx.locale());
auto w = detail::tm_writer<decltype(ctx.out()), Char>(loc, ctx.out(), time);
w.on_abbr_month();
return w.out();
}
};

template <typename Char> struct formatter<year, Char> {
template <typename Char>
struct formatter<year, Char> : private formatter<std::tm, Char> {
private:
bool use_tm_formatter_ = false;

public:
FMT_CONSTEXPR auto parse(basic_format_parse_context<Char>& 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<std::tm, Char>::parse(ctx) : it;
}

template <typename FormatContext>
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<int>(y) - 1900;
detail::get_locale loc(true, ctx.locale());
if (use_tm_formatter_) return formatter<std::tm, Char>::format(time, ctx);
detail::get_locale loc(false, ctx.locale());
auto w = detail::tm_writer<decltype(ctx.out()), Char>(loc, ctx.out(), time);
w.on_year(detail::numeric_system::standard);
return w.out();
}
};

template <typename Char>
struct formatter<year_month_day, Char> : private formatter<std::tm, Char> {
private:
bool use_tm_formatter_ = false;

public:
FMT_CONSTEXPR auto parse(basic_format_parse_context<Char>& ctx)
-> decltype(ctx.begin()) {
auto it = ctx.begin(), end = ctx.end();
use_tm_formatter_ = it != end && *it != '}';
return use_tm_formatter_ ? formatter<std::tm, Char>::parse(ctx) : it;
}

template <typename FormatContext>
auto format(year_month_day val, FormatContext& ctx) const
-> decltype(ctx.out()) {
auto time = std::tm();
time.tm_year = static_cast<int>(val.year()) - 1900;
time.tm_mon = static_cast<int>(static_cast<unsigned>(val.month())) - 1;
time.tm_mday = static_cast<int>(static_cast<unsigned>(val.day()));
if (use_tm_formatter_) return formatter<std::tm, Char>::format(time, ctx);
detail::get_locale loc(true, ctx.locale());
auto w = detail::tm_writer<decltype(ctx.out()), Char>(loc, ctx.out(), time);
w.on_iso_date();
return w.out();
}
};

template <typename Rep, typename Period, typename Char>
struct formatter<std::chrono::duration<Rep, Period>, Char> {
private:
Expand Down
4 changes: 3 additions & 1 deletion include/fmt/compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#ifndef FMT_COMPILE_H_
#define FMT_COMPILE_H_

#include <iterator> // std::back_inserter
#ifndef FMT_IMPORT_STD
# include <iterator> // std::back_inserter
#endif

#include "format.h"

Expand Down
10 changes: 6 additions & 4 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
#ifndef FMT_FORMAT_INL_H_
#define FMT_FORMAT_INL_H_

#include <algorithm>
#ifndef FMT_IMPORT_STD
# include <algorithm>
# include <cmath>
# include <exception>
#endif
#include <cerrno> // errno
#include <climits>
#include <cmath>
#include <exception>

#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) && !defined(FMT_IMPORT_STD)
# include <locale>
#endif

Expand Down
Loading

0 comments on commit ef28ade

Please sign in to comment.