Move specs to core.h

This commit is contained in:
Victor Zverovich
2021-05-13 18:28:19 -07:00
parent 08da1adcf6
commit dd2bc998ab
2 changed files with 59 additions and 59 deletions

View File

@@ -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 <typename Char> 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<Char> 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<unsigned char>(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 <typename Char> 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<Char> 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<char>;
FMT_MODULE_EXPORT_END
namespace detail {