diff --git a/include/fmt/core.h b/include/fmt/core.h index d2a6e92c..25b3427d 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1811,6 +1811,61 @@ namespace align { enum type { none, left, right, center, numeric }; } using align_t = align::type; +namespace sign { +enum type { none, minus, plus, space }; +} +using sign_t = sign::type; + +namespace detail { +void throw_format_error(const char* message); + +// Workaround an array initialization issue in gcc 4.8. +template struct fill_t { + private: + enum { max_size = 4 }; + Char data_[max_size] = {Char(' '), Char(0), Char(0), Char(0)}; + unsigned char size_ = 1; + + public: + FMT_CONSTEXPR void operator=(basic_string_view s) { + auto size = s.size(); + if (size > max_size) return throw_format_error("invalid fill"); + for (size_t i = 0; i < size; ++i) data_[i] = s[i]; + size_ = static_cast(size); + } + + constexpr size_t size() const { return size_; } + constexpr const Char* data() const { return data_; } + + FMT_CONSTEXPR Char& operator[](size_t index) { return data_[index]; } + FMT_CONSTEXPR const Char& operator[](size_t index) const { + return data_[index]; + } +}; +} // namespace detail + +// Format specifiers for built-in and string types. +template struct basic_format_specs { + int width; + int precision; + char type; + align_t align : 4; + sign_t sign : 3; + bool alt : 1; // Alternate form ('#'). + bool localized : 1; + detail::fill_t fill; + + constexpr basic_format_specs() + : width(0), + precision(-1), + type(0), + align(align::none), + sign(sign::none), + alt(false), + localized(false) {} +}; + +using format_specs = basic_format_specs; FMT_MODULE_EXPORT_END namespace detail { diff --git a/include/fmt/format.h b/include/fmt/format.h index a27fcf70..5eea9f92 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -815,6 +815,10 @@ class FMT_API format_error : public std::runtime_error { FMT_MODULE_EXPORT_END namespace detail { +inline void throw_format_error(const char* message) { + FMT_THROW(format_error(message)); +} + template struct is_integral : std::is_integral {}; template <> struct is_integral : std::true_type {}; template <> struct is_integral : std::true_type {}; @@ -1138,65 +1142,6 @@ class utf8_to_utf16 { template struct null {}; -// Workaround an array initialization issue in gcc 4.8. -template struct fill_t { - private: - enum { max_size = 4 }; - Char data_[max_size] = {Char(' '), Char(0), Char(0), Char(0)}; - unsigned char size_ = 1; - - public: - FMT_CONSTEXPR void operator=(basic_string_view s) { - auto size = s.size(); - if (size > max_size) { - FMT_THROW(format_error("invalid fill")); - return; - } - for (size_t i = 0; i < size; ++i) data_[i] = s[i]; - size_ = static_cast(size); - } - - constexpr size_t size() const { return size_; } - constexpr const Char* data() const { return data_; } - - FMT_CONSTEXPR Char& operator[](size_t index) { return data_[index]; } - FMT_CONSTEXPR const Char& operator[](size_t index) const { - return data_[index]; - } -}; -} // namespace detail -FMT_MODULE_EXPORT_BEGIN - -namespace sign { -enum type { none, minus, plus, space }; -} -using sign_t = sign::type; - -// Format specifiers for built-in and string types. -template struct basic_format_specs { - int width; - int precision; - char type; - align_t align : 4; - sign_t sign : 3; - bool alt : 1; // Alternate form ('#'). - bool localized : 1; - detail::fill_t fill; - - constexpr basic_format_specs() - : width(0), - precision(-1), - type(0), - align(align::none), - sign(sign::none), - alt(false), - localized(false) {} -}; - -using format_specs = basic_format_specs; - -FMT_MODULE_EXPORT_END -namespace detail { namespace dragonbox { // Type-specific information that Dragonbox uses.