mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-25 19:50:05 +00:00
Follow standard naming conventions
This commit is contained in:
parent
6a2ff287b2
commit
c333dca065
@ -70,18 +70,17 @@
|
||||
|
||||
// Dummy implementations of strerror_r and strerror_s called if corresponding
|
||||
// system functions are not available.
|
||||
static inline fmt::internal::Null<> strerror_r(int, char *, ...) {
|
||||
return fmt::internal::Null<>();
|
||||
static inline fmt::internal::null<> strerror_r(int, char *, ...) {
|
||||
return fmt::internal::null<>();
|
||||
}
|
||||
static inline fmt::internal::Null<> strerror_s(char *, std::size_t, ...) {
|
||||
return fmt::internal::Null<>();
|
||||
static inline fmt::internal::null<> strerror_s(char *, std::size_t, ...) {
|
||||
return fmt::internal::null<>();
|
||||
}
|
||||
|
||||
namespace fmt {
|
||||
|
||||
FMT_FUNC internal::RuntimeError::~RuntimeError() throw() {}
|
||||
FMT_FUNC format_error::~format_error() throw() {}
|
||||
FMT_FUNC SystemError::~SystemError() throw() {}
|
||||
FMT_FUNC system_error::~system_error() throw() {}
|
||||
|
||||
namespace {
|
||||
|
||||
@ -146,7 +145,7 @@ int safe_strerror(
|
||||
}
|
||||
|
||||
// Handle the case when strerror_r is not available.
|
||||
int handle(internal::Null<>) {
|
||||
int handle(internal::null<>) {
|
||||
return fallback(strerror_s(buffer_, buffer_size_, error_code_));
|
||||
}
|
||||
|
||||
@ -158,7 +157,7 @@ int safe_strerror(
|
||||
}
|
||||
|
||||
// Fallback to strerror if strerror_r and strerror_s are not available.
|
||||
int fallback(internal::Null<>) {
|
||||
int fallback(internal::null<>) {
|
||||
errno = 0;
|
||||
buffer_ = strerror(error_code_);
|
||||
return errno;
|
||||
@ -214,7 +213,7 @@ void report_error(FormatFunc func, int error_code,
|
||||
}
|
||||
} // namespace
|
||||
|
||||
FMT_FUNC void SystemError::init(
|
||||
FMT_FUNC void system_error::init(
|
||||
int err_code, CStringRef format_str, args args) {
|
||||
error_code_ = err_code;
|
||||
memory_buffer buffer;
|
||||
@ -301,28 +300,28 @@ FMT_FUNC void internal::report_unknown_type(char code, const char *type) {
|
||||
FMT_FUNC internal::utf8_to_utf16::utf8_to_utf16(string_view s) {
|
||||
static const char ERROR_MSG[] = "cannot convert string from UTF-8 to UTF-16";
|
||||
if (s.size() > INT_MAX)
|
||||
FMT_THROW(WindowsError(ERROR_INVALID_PARAMETER, ERROR_MSG));
|
||||
FMT_THROW(windows_error(ERROR_INVALID_PARAMETER, ERROR_MSG));
|
||||
int s_size = static_cast<int>(s.size());
|
||||
int length = MultiByteToWideChar(
|
||||
CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s_size, 0, 0);
|
||||
if (length == 0)
|
||||
FMT_THROW(WindowsError(GetLastError(), ERROR_MSG));
|
||||
FMT_THROW(windows_error(GetLastError(), ERROR_MSG));
|
||||
buffer_.resize(length + 1);
|
||||
length = MultiByteToWideChar(
|
||||
CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s_size, &buffer_[0], length);
|
||||
if (length == 0)
|
||||
FMT_THROW(WindowsError(GetLastError(), ERROR_MSG));
|
||||
FMT_THROW(windows_error(GetLastError(), ERROR_MSG));
|
||||
buffer_[length] = 0;
|
||||
}
|
||||
|
||||
FMT_FUNC internal::UTF16ToUTF8::UTF16ToUTF8(wstring_view s) {
|
||||
FMT_FUNC internal::utf16_to_utf8::utf16_to_utf8(wstring_view s) {
|
||||
if (int error_code = convert(s)) {
|
||||
FMT_THROW(WindowsError(error_code,
|
||||
FMT_THROW(windows_error(error_code,
|
||||
"cannot convert string from UTF-16 to UTF-8"));
|
||||
}
|
||||
}
|
||||
|
||||
FMT_FUNC int internal::UTF16ToUTF8::convert(wstring_view s) {
|
||||
FMT_FUNC int internal::utf16_to_utf8::convert(wstring_view s) {
|
||||
if (s.size() > INT_MAX)
|
||||
return ERROR_INVALID_PARAMETER;
|
||||
int s_size = static_cast<int>(s.size());
|
||||
@ -338,7 +337,7 @@ FMT_FUNC int internal::UTF16ToUTF8::convert(wstring_view s) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
FMT_FUNC void WindowsError::init(
|
||||
FMT_FUNC void windows_error::init(
|
||||
int err_code, CStringRef format_str, args args) {
|
||||
error_code_ = err_code;
|
||||
memory_buffer buffer;
|
||||
@ -359,7 +358,7 @@ FMT_FUNC void internal::format_windows_error(
|
||||
0, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
system_message, static_cast<uint32_t>(buffer.size()), 0);
|
||||
if (result != 0) {
|
||||
UTF16ToUTF8 utf8_message;
|
||||
utf16_to_utf8 utf8_message;
|
||||
if (utf8_message.convert(system_message) == ERROR_SUCCESS) {
|
||||
basic_writer<char> w(out);
|
||||
w.write(message);
|
||||
@ -459,7 +458,7 @@ template struct internal::basic_data<void>;
|
||||
|
||||
template void basic_fixed_buffer<char>::grow(std::size_t);
|
||||
|
||||
template void internal::ArgMap<context>::init(const args &args);
|
||||
template void internal::arg_map<context>::init(const args &args);
|
||||
|
||||
template void printf_context<char>::format(buffer &);
|
||||
|
||||
@ -477,7 +476,7 @@ template class basic_context<wchar_t>;
|
||||
|
||||
template void basic_fixed_buffer<wchar_t>::grow(std::size_t);
|
||||
|
||||
template void internal::ArgMap<wcontext>::init(const wargs &args);
|
||||
template void internal::arg_map<wcontext>::init(const wargs &args);
|
||||
|
||||
template void printf_context<wchar_t>::format(wbuffer &);
|
||||
|
||||
|
259
fmt/format.h
259
fmt/format.h
@ -555,7 +555,7 @@ inline typename make_unsigned<Int>::type to_unsigned(Int value) {
|
||||
return static_cast<typename make_unsigned<Int>::type>(value);
|
||||
}
|
||||
|
||||
// The number of characters to store in the MemoryBuffer object itself
|
||||
// The number of characters to store in the basic_memory_buffer object itself
|
||||
// to avoid dynamic memory allocation.
|
||||
enum { INLINE_BUFFER_SIZE = 500 };
|
||||
|
||||
@ -1034,13 +1034,13 @@ class utf8_to_utf16 {
|
||||
|
||||
// A converter from UTF-16 to UTF-8.
|
||||
// It is only provided for Windows since other systems support UTF-8 natively.
|
||||
class UTF16ToUTF8 {
|
||||
class utf16_to_utf8 {
|
||||
private:
|
||||
memory_buffer buffer_;
|
||||
|
||||
public:
|
||||
UTF16ToUTF8() {}
|
||||
FMT_API explicit UTF16ToUTF8(wstring_view s);
|
||||
utf16_to_utf8() {}
|
||||
FMT_API explicit utf16_to_utf8(wstring_view s);
|
||||
operator string_view() const { return string_view(&buffer_[0], size()); }
|
||||
size_t size() const { return buffer_.size() - 1; }
|
||||
const char *c_str() const { return &buffer_[0]; }
|
||||
@ -1057,59 +1057,59 @@ FMT_API void format_windows_error(fmt::buffer &out, int error_code,
|
||||
#endif
|
||||
|
||||
template <typename T = void>
|
||||
struct Null {};
|
||||
struct null {};
|
||||
|
||||
// A helper class template to enable or disable overloads taking wide
|
||||
// characters and strings in value's constructor.
|
||||
template <typename T, typename Char>
|
||||
struct WCharHelper {
|
||||
typedef Null<T> Supported;
|
||||
typedef T Unsupported;
|
||||
struct wchar_helper {
|
||||
typedef null<T> supported;
|
||||
typedef T unsupported;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct WCharHelper<T, wchar_t> {
|
||||
typedef T Supported;
|
||||
typedef Null<T> Unsupported;
|
||||
struct wchar_helper<T, wchar_t> {
|
||||
typedef T supported;
|
||||
typedef null<T> unsupported;
|
||||
};
|
||||
|
||||
typedef char Yes[1];
|
||||
typedef char No[2];
|
||||
typedef char yes[1];
|
||||
typedef char no[2];
|
||||
|
||||
template <typename T>
|
||||
T &get();
|
||||
|
||||
// These are non-members to workaround an overload resolution bug in bcc32.
|
||||
Yes &convert(fmt::ulong_long);
|
||||
No &convert(...);
|
||||
yes &convert(fmt::ulong_long);
|
||||
no &convert(...);
|
||||
|
||||
template<typename T, bool ENABLE_CONVERSION>
|
||||
struct ConvertToIntImpl {
|
||||
struct convert_to_int_impl {
|
||||
enum { value = ENABLE_CONVERSION };
|
||||
};
|
||||
|
||||
template<typename T, bool ENABLE_CONVERSION>
|
||||
struct ConvertToIntImpl2 {
|
||||
struct convert_to_int_impl2 {
|
||||
enum { value = false };
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct ConvertToIntImpl2<T, true> {
|
||||
struct convert_to_int_impl2<T, true> {
|
||||
enum {
|
||||
// Don't convert numeric types.
|
||||
value = ConvertToIntImpl<T, !std::numeric_limits<T>::is_specialized>::value
|
||||
value = convert_to_int_impl<
|
||||
T, !std::numeric_limits<T>::is_specialized>::value
|
||||
};
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct ConvertToInt {
|
||||
enum { enable_conversion = sizeof(convert(get<T>())) == sizeof(Yes) };
|
||||
enum { value = ConvertToIntImpl2<T, enable_conversion>::value };
|
||||
struct convert_to_int {
|
||||
enum { enable_conversion = sizeof(convert(get<T>())) == sizeof(yes) };
|
||||
enum { value = convert_to_int_impl2<T, enable_conversion>::value };
|
||||
};
|
||||
|
||||
#define FMT_DISABLE_CONVERSION_TO_INT(Type) \
|
||||
template <> \
|
||||
struct ConvertToInt<Type> { enum { value = 0 }; }
|
||||
struct convert_to_int<Type> { enum { value = 0 }; }
|
||||
|
||||
// Silence warnings about convering float to int.
|
||||
FMT_DISABLE_CONVERSION_TO_INT(float);
|
||||
@ -1141,18 +1141,18 @@ struct custom_value {
|
||||
};
|
||||
|
||||
template <typename Char>
|
||||
struct NamedArg;
|
||||
struct named_arg;
|
||||
|
||||
template <typename T>
|
||||
struct IsNamedArg : std::false_type {};
|
||||
struct is_named_arg : std::false_type {};
|
||||
|
||||
template <typename Char>
|
||||
struct IsNamedArg< NamedArg<Char> > : std::true_type {};
|
||||
struct is_named_arg< named_arg<Char> > : std::true_type {};
|
||||
|
||||
template <typename T>
|
||||
constexpr Type gettype() {
|
||||
return IsNamedArg<T>::value ?
|
||||
NAMED_ARG : (ConvertToInt<T>::value ? INT : CUSTOM);
|
||||
return is_named_arg<T>::value ?
|
||||
NAMED_ARG : (convert_to_int<T>::value ? INT : CUSTOM);
|
||||
}
|
||||
|
||||
template <> constexpr Type gettype<bool>() { return BOOL; }
|
||||
@ -1236,12 +1236,12 @@ class value {
|
||||
// fmt::format("{}", L"test");
|
||||
// To fix this, use a wide format string: fmt::format(L"{}", L"test").
|
||||
#if !FMT_MSC_VER || defined(_NATIVE_WCHAR_T_DEFINED)
|
||||
value(typename WCharHelper<wchar_t, Char>::Unsupported);
|
||||
value(typename wchar_helper<wchar_t, Char>::unsupported);
|
||||
#endif
|
||||
value(typename WCharHelper<wchar_t *, Char>::Unsupported);
|
||||
value(typename WCharHelper<const wchar_t *, Char>::Unsupported);
|
||||
value(typename WCharHelper<const std::wstring &, Char>::Unsupported);
|
||||
value(typename WCharHelper<wstring_view, Char>::Unsupported);
|
||||
value(typename wchar_helper<wchar_t *, Char>::unsupported);
|
||||
value(typename wchar_helper<const wchar_t *, Char>::unsupported);
|
||||
value(typename wchar_helper<const std::wstring &, Char>::unsupported);
|
||||
value(typename wchar_helper<wstring_view, Char>::unsupported);
|
||||
|
||||
void set_string(string_view str) {
|
||||
this->string.value = str.data();
|
||||
@ -1305,7 +1305,7 @@ class value {
|
||||
FMT_MAKE_VALUE(char, int_value, CHAR)
|
||||
|
||||
#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
|
||||
typedef typename WCharHelper<wchar_t, Char>::Supported WChar;
|
||||
typedef typename wchar_helper<wchar_t, Char>::supported WChar;
|
||||
value(WChar value) {
|
||||
static_assert(internal::type<WChar>() == internal::CHAR, "invalid type");
|
||||
this->int_value = value;
|
||||
@ -1329,7 +1329,7 @@ class value {
|
||||
FMT_MAKE_VALUE_(CStringRef, string.value, CSTRING, value.c_str())
|
||||
|
||||
#define FMT_MAKE_WSTR_VALUE(Type, TYPE) \
|
||||
value(typename WCharHelper<Type, Char>::Supported value) { \
|
||||
value(typename wchar_helper<Type, Char>::supported value) { \
|
||||
static_assert(internal::type<Type>() == internal::TYPE, "invalid type"); \
|
||||
set_string(value); \
|
||||
}
|
||||
@ -1344,7 +1344,7 @@ class value {
|
||||
|
||||
template <typename T>
|
||||
value(const T &value,
|
||||
typename enable_if<!ConvertToInt<T>::value, int>::type = 0) {
|
||||
typename enable_if<!convert_to_int<T>::value, int>::type = 0) {
|
||||
static_assert(internal::type<T>() == internal::CUSTOM, "invalid type");
|
||||
this->custom.value = &value;
|
||||
this->custom.format = &format_custom_arg<T>;
|
||||
@ -1352,7 +1352,7 @@ class value {
|
||||
|
||||
template <typename T>
|
||||
value(const T &value,
|
||||
typename enable_if<ConvertToInt<T>::value, int>::type = 0) {
|
||||
typename enable_if<convert_to_int<T>::value, int>::type = 0) {
|
||||
static_assert(internal::type<T>() == internal::INT, "invalid type");
|
||||
this->int_value = value;
|
||||
}
|
||||
@ -1360,16 +1360,16 @@ class value {
|
||||
// Additional template param `Char_` is needed here because make_type always
|
||||
// uses char.
|
||||
template <typename Char_>
|
||||
value(const NamedArg<Char_> &value) {
|
||||
value(const named_arg<Char_> &value) {
|
||||
static_assert(
|
||||
internal::type<const NamedArg<Char_> &>() == internal::NAMED_ARG,
|
||||
internal::type<const named_arg<Char_> &>() == internal::NAMED_ARG,
|
||||
"invalid type");
|
||||
this->pointer = &value;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
class ArgMap;
|
||||
class arg_map;
|
||||
|
||||
template <typename Context, typename T>
|
||||
basic_arg<Context> make_arg(const T &value);
|
||||
@ -1381,7 +1381,7 @@ template <typename Context>
|
||||
class basic_args;
|
||||
|
||||
// A formatting argument. It is a trivially copyable/constructible type to
|
||||
// allow storage in internal::MemoryBuffer.
|
||||
// allow storage in basic_memory_buffer.
|
||||
template <typename Context>
|
||||
class basic_arg {
|
||||
private:
|
||||
@ -1396,7 +1396,7 @@ class basic_arg {
|
||||
visit(Visitor &&vis, basic_arg<Ctx> arg);
|
||||
|
||||
friend class basic_args<Context>;
|
||||
friend class internal::ArgMap<Context>;
|
||||
friend class internal::arg_map<Context>;
|
||||
|
||||
public:
|
||||
basic_arg() : type_(internal::NONE) {}
|
||||
@ -1476,8 +1476,8 @@ basic_arg<Context> make_arg(const T &value) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
template <typename T, T> struct LConvCheck {
|
||||
LConvCheck(int) {}
|
||||
template <typename T, T> struct lconv_check {
|
||||
lconv_check(int) {}
|
||||
};
|
||||
|
||||
// Returns the thousands separator for the current locale.
|
||||
@ -1485,7 +1485,7 @@ template <typename T, T> struct LConvCheck {
|
||||
// ``lconv`` is stubbed as an empty struct.
|
||||
template <typename LConv>
|
||||
inline string_view thousands_sep(
|
||||
LConv *lc, LConvCheck<char *LConv::*, &LConv::thousands_sep> = 0) {
|
||||
LConv *lc, lconv_check<char *LConv::*, &LConv::thousands_sep> = 0) {
|
||||
return lc->thousands_sep;
|
||||
}
|
||||
|
||||
@ -1521,22 +1521,16 @@ void format_value(basic_buffer<Char> &, const T &, Formatter &, const Char *) {
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
struct NamedArg : basic_arg<Context> {
|
||||
struct named_arg : basic_arg<Context> {
|
||||
typedef typename Context::char_type Char;
|
||||
|
||||
basic_string_view<Char> name;
|
||||
|
||||
template <typename T>
|
||||
NamedArg(basic_string_view<Char> argname, const T &value)
|
||||
named_arg(basic_string_view<Char> argname, const T &value)
|
||||
: basic_arg<Context>(make_arg<Context>(value)), name(argname) {}
|
||||
};
|
||||
|
||||
class RuntimeError : public std::runtime_error {
|
||||
protected:
|
||||
RuntimeError() : std::runtime_error("") {}
|
||||
~RuntimeError() throw();
|
||||
};
|
||||
|
||||
template <typename Arg, typename... Args>
|
||||
constexpr uint64_t make_type() {
|
||||
return type<Arg>() | (make_type<Args...>() << 4);
|
||||
@ -1625,7 +1619,7 @@ class basic_args {
|
||||
(types_ & (mask << shift)) >> shift);
|
||||
}
|
||||
|
||||
friend class internal::ArgMap<Context>;
|
||||
friend class internal::arg_map<Context>;
|
||||
|
||||
void set_data(const internal::value<Context> *values) { values_ = values; }
|
||||
void set_data(const format_arg *args) { args_ = args; }
|
||||
@ -1674,7 +1668,7 @@ class basic_args {
|
||||
typedef basic_args<context> args;
|
||||
typedef basic_args<wcontext> wargs;
|
||||
|
||||
enum Alignment {
|
||||
enum alignment {
|
||||
ALIGN_DEFAULT, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_NUMERIC
|
||||
};
|
||||
|
||||
@ -1736,53 +1730,26 @@ constexpr format_spec_factory<width_spec> width;
|
||||
constexpr format_spec_factory<type_spec> type;
|
||||
|
||||
// An empty format specifier.
|
||||
struct EmptySpec {};
|
||||
struct empty_spec {};
|
||||
|
||||
// A type specifier.
|
||||
template <char TYPE>
|
||||
struct TypeSpec : EmptySpec {
|
||||
Alignment align() const { return ALIGN_DEFAULT; }
|
||||
unsigned width() const { return 0; }
|
||||
int precision() const { return -1; }
|
||||
bool flag(unsigned) const { return false; }
|
||||
char type() const { return TYPE; }
|
||||
char fill() const { return ' '; }
|
||||
};
|
||||
|
||||
// A width specifier.
|
||||
struct WidthSpec {
|
||||
// An alignment specifier.
|
||||
struct AlignSpec : empty_spec {
|
||||
unsigned width_;
|
||||
// Fill is always wchar_t and cast to char if necessary to avoid having
|
||||
// two specialization of WidthSpec and its subclasses.
|
||||
wchar_t fill_;
|
||||
alignment align_;
|
||||
|
||||
WidthSpec(unsigned width, wchar_t fill) : width_(width), fill_(fill) {}
|
||||
AlignSpec(unsigned width, wchar_t fill, alignment align = ALIGN_DEFAULT)
|
||||
: width_(width), fill_(fill), align_(align) {}
|
||||
|
||||
unsigned width() const { return width_; }
|
||||
wchar_t fill() const { return fill_; }
|
||||
};
|
||||
|
||||
// An alignment specifier.
|
||||
struct AlignSpec : WidthSpec {
|
||||
Alignment align_;
|
||||
|
||||
AlignSpec(unsigned width, wchar_t fill, Alignment align = ALIGN_DEFAULT)
|
||||
: WidthSpec(width, fill), align_(align) {}
|
||||
|
||||
Alignment align() const { return align_; }
|
||||
alignment align() const { return align_; }
|
||||
|
||||
int precision() const { return -1; }
|
||||
};
|
||||
|
||||
// An alignment and type specifier.
|
||||
template <char TYPE>
|
||||
struct AlignTypeSpec : AlignSpec {
|
||||
AlignTypeSpec(unsigned width, wchar_t fill) : AlignSpec(width, fill) {}
|
||||
|
||||
bool flag(unsigned) const { return false; }
|
||||
char type() const { return TYPE; }
|
||||
};
|
||||
|
||||
// Format specifiers.
|
||||
template <typename Char>
|
||||
class basic_format_specs : public AlignSpec {
|
||||
@ -1832,7 +1799,7 @@ typedef basic_format_specs<char> format_specs;
|
||||
namespace internal {
|
||||
|
||||
template <typename Context>
|
||||
class ArgMap {
|
||||
class arg_map {
|
||||
private:
|
||||
typedef typename Context::char_type Char;
|
||||
typedef std::vector<
|
||||
@ -1857,10 +1824,10 @@ class ArgMap {
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
void ArgMap<Context>::init(const basic_args<Context> &args) {
|
||||
void arg_map<Context>::init(const basic_args<Context> &args) {
|
||||
if (!map_.empty())
|
||||
return;
|
||||
typedef internal::NamedArg<Context> NamedArg;
|
||||
typedef internal::named_arg<Context> NamedArg;
|
||||
const NamedArg *named_arg = 0;
|
||||
bool use_values =
|
||||
args.type(MAX_PACKED_ARGS - 1) == internal::NONE;
|
||||
@ -1902,7 +1869,7 @@ void ArgMap<Context>::init(const basic_args<Context> &args) {
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
class ArgFormatterBase {
|
||||
class arg_formatter_base {
|
||||
public:
|
||||
typedef basic_format_specs<Char> format_specs;
|
||||
|
||||
@ -1910,7 +1877,7 @@ class ArgFormatterBase {
|
||||
basic_writer<Char> writer_;
|
||||
format_specs &spec_;
|
||||
|
||||
FMT_DISALLOW_COPY_AND_ASSIGN(ArgFormatterBase);
|
||||
FMT_DISALLOW_COPY_AND_ASSIGN(arg_formatter_base);
|
||||
|
||||
void write_pointer(const void *p) {
|
||||
spec_.flags_ = HASH_FLAG;
|
||||
@ -1950,7 +1917,7 @@ class ArgFormatterBase {
|
||||
public:
|
||||
typedef Char char_type;
|
||||
|
||||
ArgFormatterBase(basic_buffer<Char> &b, format_specs &s)
|
||||
arg_formatter_base(basic_buffer<Char> &b, format_specs &s)
|
||||
: writer_(b), spec_(s) {}
|
||||
|
||||
void operator()(monostate) {
|
||||
@ -2078,11 +2045,11 @@ class context_base {
|
||||
|
||||
/** The default argument formatter. */
|
||||
template <typename Char>
|
||||
class arg_formatter : public internal::ArgFormatterBase<Char> {
|
||||
class arg_formatter : public internal::arg_formatter_base<Char> {
|
||||
private:
|
||||
basic_context<Char> &ctx_;
|
||||
|
||||
typedef internal::ArgFormatterBase<Char> Base;
|
||||
typedef internal::arg_formatter_base<Char> Base;
|
||||
|
||||
public:
|
||||
typedef typename Base::format_specs format_specs;
|
||||
@ -2097,9 +2064,9 @@ class arg_formatter : public internal::ArgFormatterBase<Char> {
|
||||
*/
|
||||
arg_formatter(basic_buffer<Char> &buffer, basic_context<Char> &ctx,
|
||||
format_specs &spec)
|
||||
: internal::ArgFormatterBase<Char>(buffer, spec), ctx_(ctx) {}
|
||||
: internal::arg_formatter_base<Char>(buffer, spec), ctx_(ctx) {}
|
||||
|
||||
using internal::ArgFormatterBase<Char>::operator();
|
||||
using internal::arg_formatter_base<Char>::operator();
|
||||
|
||||
/** Formats an argument of a custom (user-defined) type. */
|
||||
void operator()(internal::custom_value<Char> c) {
|
||||
@ -2115,7 +2082,7 @@ class basic_context :
|
||||
typedef Char char_type;
|
||||
|
||||
private:
|
||||
internal::ArgMap<basic_context<Char>> map_;
|
||||
internal::arg_map<basic_context<Char>> map_;
|
||||
|
||||
FMT_DISALLOW_COPY_AND_ASSIGN(basic_context);
|
||||
|
||||
@ -2149,40 +2116,41 @@ class basic_context :
|
||||
An error returned by an operating system or a language runtime,
|
||||
for example a file opening error.
|
||||
*/
|
||||
class SystemError : public internal::RuntimeError {
|
||||
class system_error : public std::runtime_error {
|
||||
private:
|
||||
void init(int err_code, CStringRef format_str, args args);
|
||||
|
||||
protected:
|
||||
int error_code_;
|
||||
|
||||
SystemError() {}
|
||||
system_error() : std::runtime_error("") {}
|
||||
|
||||
public:
|
||||
/**
|
||||
\rst
|
||||
Constructs a :class:`fmt::SystemError` object with a description
|
||||
Constructs a :class:`fmt::system_error` object with a description
|
||||
formatted with `fmt::format_system_error`. *message* and additional
|
||||
arguments passed into the constructor are formatted similarly to
|
||||
`fmt::format`.
|
||||
|
||||
**Example**::
|
||||
|
||||
// This throws a SystemError with the description
|
||||
// This throws a system_error with the description
|
||||
// cannot open file 'madeup': No such file or directory
|
||||
// or similar (system message may vary).
|
||||
const char *filename = "madeup";
|
||||
std::FILE *file = std::fopen(filename, "r");
|
||||
if (!file)
|
||||
throw fmt::SystemError(errno, "cannot open file '{}'", filename);
|
||||
throw fmt::system_error(errno, "cannot open file '{}'", filename);
|
||||
\endrst
|
||||
*/
|
||||
template <typename... Args>
|
||||
SystemError(int error_code, CStringRef message, const Args & ... args) {
|
||||
system_error(int error_code, CStringRef message, const Args & ... args)
|
||||
: std::runtime_error("") {
|
||||
init(error_code, message, make_args(args...));
|
||||
}
|
||||
|
||||
~SystemError() throw();
|
||||
~system_error() throw();
|
||||
|
||||
int error_code() const { return error_code_; }
|
||||
};
|
||||
@ -2292,7 +2260,7 @@ class basic_writer {
|
||||
|
||||
// Prepare a buffer for integer formatting.
|
||||
CharPtr prepare_int_buffer(unsigned num_digits,
|
||||
const EmptySpec &, const char *prefix, unsigned prefix_size) {
|
||||
const empty_spec &, const char *prefix, unsigned prefix_size) {
|
||||
unsigned size = prefix_size + num_digits;
|
||||
CharPtr p = grow_buffer(size);
|
||||
std::uninitialized_copy(prefix, prefix + prefix_size, p);
|
||||
@ -2322,9 +2290,9 @@ class basic_writer {
|
||||
// and strings to a char buffer. If you want to print a wide string as a
|
||||
// pointer as std::ostream does, cast it to const void*.
|
||||
// Do not implement!
|
||||
void operator<<(typename internal::WCharHelper<wchar_t, Char>::Unsupported);
|
||||
void operator<<(typename internal::wchar_helper<wchar_t, Char>::unsupported);
|
||||
void operator<<(
|
||||
typename internal::WCharHelper<const wchar_t *, Char>::Unsupported);
|
||||
typename internal::wchar_helper<const wchar_t *, Char>::unsupported);
|
||||
|
||||
// Appends floating-point length specifier to the format string.
|
||||
// The second argument is only used for overload resolution.
|
||||
@ -2336,7 +2304,7 @@ class basic_writer {
|
||||
void append_float_length(Char *&, T) {}
|
||||
|
||||
template <typename Char_>
|
||||
friend class internal::ArgFormatterBase;
|
||||
friend class internal::arg_formatter_base;
|
||||
|
||||
template <typename Char_>
|
||||
friend class printf_arg_formatter;
|
||||
@ -2427,7 +2395,7 @@ class basic_writer {
|
||||
buffer_.push_back(value);
|
||||
}
|
||||
|
||||
void write(typename internal::WCharHelper<wchar_t, Char>::Supported value) {
|
||||
void write(typename internal::wchar_helper<wchar_t, Char>::supported value) {
|
||||
buffer_.push_back(value);
|
||||
}
|
||||
|
||||
@ -2442,7 +2410,7 @@ class basic_writer {
|
||||
}
|
||||
|
||||
void write(
|
||||
typename internal::WCharHelper<string_view, Char>::Supported value) {
|
||||
typename internal::wchar_helper<string_view, Char>::supported value) {
|
||||
const char *str = value.data();
|
||||
buffer_.append(str, str + value.size());
|
||||
}
|
||||
@ -2522,7 +2490,7 @@ typename basic_writer<Char>::CharPtr basic_writer<Char>::prepare_int_buffer(
|
||||
unsigned num_digits, const Spec &spec,
|
||||
const char *prefix, unsigned prefix_size) {
|
||||
unsigned width = spec.width();
|
||||
Alignment align = spec.align();
|
||||
alignment align = spec.align();
|
||||
Char fill = internal::char_traits<Char>::cast(spec.fill());
|
||||
if (spec.precision() > static_cast<int>(num_digits)) {
|
||||
// Octal prefix '0' is counted as a digit, so ignore it if precision
|
||||
@ -2833,14 +2801,14 @@ FMT_API void report_system_error(int error_code,
|
||||
#if FMT_USE_WINDOWS_H
|
||||
|
||||
/** A Windows error. */
|
||||
class WindowsError : public SystemError {
|
||||
class windows_error : public system_error {
|
||||
private:
|
||||
FMT_API void init(int error_code, CStringRef format_str, args args);
|
||||
|
||||
public:
|
||||
/**
|
||||
\rst
|
||||
Constructs a :class:`fmt::WindowsError` object with the description
|
||||
Constructs a :class:`fmt::windows_error` object with the description
|
||||
of the form
|
||||
|
||||
.. parsed-literal::
|
||||
@ -2854,20 +2822,20 @@ class WindowsError : public SystemError {
|
||||
|
||||
**Example**::
|
||||
|
||||
// This throws a WindowsError with the description
|
||||
// This throws a windows_error with the description
|
||||
// cannot open file 'madeup': The system cannot find the file specified.
|
||||
// or similar (system message may vary).
|
||||
const char *filename = "madeup";
|
||||
LPOFSTRUCT of = LPOFSTRUCT();
|
||||
HFILE file = OpenFile(filename, &of, OF_READ);
|
||||
if (file == HFILE_ERROR) {
|
||||
throw fmt::WindowsError(GetLastError(),
|
||||
"cannot open file '{}'", filename);
|
||||
throw fmt::windows_error(GetLastError(),
|
||||
"cannot open file '{}'", filename);
|
||||
}
|
||||
\endrst
|
||||
*/
|
||||
template <typename... Args>
|
||||
WindowsError(int error_code, CStringRef message, const Args & ... args) {
|
||||
windows_error(int error_code, CStringRef message, const Args & ... args) {
|
||||
init(error_code, message, make_args(args...));
|
||||
}
|
||||
};
|
||||
@ -3098,22 +3066,22 @@ inline void format_decimal(char *&buffer, T value) {
|
||||
\endrst
|
||||
*/
|
||||
template <typename T>
|
||||
inline internal::NamedArg<context> arg(string_view name, const T &arg) {
|
||||
return internal::NamedArg<context>(name, arg);
|
||||
inline internal::named_arg<context> arg(string_view name, const T &arg) {
|
||||
return internal::named_arg<context>(name, arg);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline internal::NamedArg<wcontext> arg(wstring_view name, const T &arg) {
|
||||
return internal::NamedArg<wcontext>(name, arg);
|
||||
inline internal::named_arg<wcontext> arg(wstring_view name, const T &arg) {
|
||||
return internal::named_arg<wcontext>(name, arg);
|
||||
}
|
||||
|
||||
// The following two functions are deleted intentionally to disable
|
||||
// nested named arguments as in ``format("{}", arg("a", arg("b", 42)))``.
|
||||
template <typename Context>
|
||||
void arg(string_view, const internal::NamedArg<Context>&)
|
||||
void arg(string_view, const internal::named_arg<Context>&)
|
||||
FMT_DELETED_OR_UNDEFINED;
|
||||
template <typename Context>
|
||||
void arg(wstring_view, const internal::NamedArg<Context>&)
|
||||
void arg(wstring_view, const internal::named_arg<Context>&)
|
||||
FMT_DELETED_OR_UNDEFINED;
|
||||
}
|
||||
|
||||
@ -3163,7 +3131,8 @@ inline void require_numeric_argument(
|
||||
}
|
||||
}
|
||||
|
||||
struct IsUnsigned {
|
||||
// An argument visitor that checks if argument is unsigned.
|
||||
struct is_unsigned {
|
||||
template <typename T>
|
||||
typename std::enable_if<std::is_unsigned<T>::value, bool>::type
|
||||
operator()(T value) {
|
||||
@ -3181,7 +3150,7 @@ template <typename Char, typename Context>
|
||||
void check_sign(const Char *&s, const basic_arg<Context> &arg) {
|
||||
char sign = static_cast<char>(*s);
|
||||
require_numeric_argument(arg, sign);
|
||||
if (visit(IsUnsigned(), arg)) {
|
||||
if (visit(is_unsigned(), arg)) {
|
||||
FMT_THROW(format_error(fmt::format(
|
||||
"format specifier '{}' requires signed argument", sign)));
|
||||
}
|
||||
@ -3189,13 +3158,13 @@ void check_sign(const Char *&s, const basic_arg<Context> &arg) {
|
||||
}
|
||||
|
||||
template <typename Char, typename Context>
|
||||
class CustomFormatter {
|
||||
class custom_formatter {
|
||||
private:
|
||||
basic_buffer<Char> &buffer_;
|
||||
Context &ctx_;
|
||||
|
||||
public:
|
||||
CustomFormatter(basic_buffer<Char> &buffer, Context &ctx)
|
||||
custom_formatter(basic_buffer<Char> &buffer, Context &ctx)
|
||||
: buffer_(buffer), ctx_(ctx) {}
|
||||
|
||||
bool operator()(internal::custom_value<Char> custom) {
|
||||
@ -3208,16 +3177,16 @@ class CustomFormatter {
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct IsInteger {
|
||||
struct is_integer {
|
||||
enum {
|
||||
value = std::is_integral<T>::value && !std::is_same<T, bool>::value &&
|
||||
!std::is_same<T, char>::value && !std::is_same<T, wchar_t>::value
|
||||
};
|
||||
};
|
||||
|
||||
struct WidthHandler {
|
||||
struct width_handler {
|
||||
template <typename T>
|
||||
typename std::enable_if<IsInteger<T>::value, ulong_long>::type
|
||||
typename std::enable_if<is_integer<T>::value, ulong_long>::type
|
||||
operator()(T value) {
|
||||
if (is_negative(value))
|
||||
FMT_THROW(format_error("negative width"));
|
||||
@ -3225,16 +3194,16 @@ struct WidthHandler {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename std::enable_if<!IsInteger<T>::value, ulong_long>::type
|
||||
typename std::enable_if<!is_integer<T>::value, ulong_long>::type
|
||||
operator()(T value) {
|
||||
FMT_THROW(format_error("width is not integer"));
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct PrecisionHandler {
|
||||
struct precision_handler {
|
||||
template <typename T>
|
||||
typename std::enable_if<IsInteger<T>::value, ulong_long>::type
|
||||
typename std::enable_if<is_integer<T>::value, ulong_long>::type
|
||||
operator()(T value) {
|
||||
if (is_negative(value))
|
||||
FMT_THROW(format_error("negative precision"));
|
||||
@ -3242,7 +3211,7 @@ struct PrecisionHandler {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename std::enable_if<!IsInteger<T>::value, ulong_long>::type
|
||||
typename std::enable_if<!is_integer<T>::value, ulong_long>::type
|
||||
operator()(T value) {
|
||||
FMT_THROW(format_error("precision is not integer"));
|
||||
return 0;
|
||||
@ -3297,7 +3266,7 @@ void do_format_arg(basic_buffer<Char> &buffer, basic_arg<Context> arg,
|
||||
const Char *&s = ctx.ptr();
|
||||
basic_format_specs<Char> spec;
|
||||
if (*s == ':') {
|
||||
if (visit(internal::CustomFormatter<Char, Context>(buffer, ctx), arg))
|
||||
if (visit(internal::custom_formatter<Char, Context>(buffer, ctx), arg))
|
||||
return;
|
||||
++s;
|
||||
// Parse fill and alignment.
|
||||
@ -3372,7 +3341,7 @@ void do_format_arg(basic_buffer<Char> &buffer, basic_arg<Context> arg,
|
||||
auto width_arg = ctx.parse_arg_id();
|
||||
if (*s++ != '}')
|
||||
FMT_THROW(format_error("invalid format string"));
|
||||
ulong_long width = visit(internal::WidthHandler(), width_arg);
|
||||
ulong_long width = visit(internal::width_handler(), width_arg);
|
||||
if (width > (std::numeric_limits<int>::max)())
|
||||
FMT_THROW(format_error("number is too big"));
|
||||
spec.width_ = static_cast<int>(width);
|
||||
@ -3390,7 +3359,7 @@ void do_format_arg(basic_buffer<Char> &buffer, basic_arg<Context> arg,
|
||||
if (*s++ != '}')
|
||||
FMT_THROW(format_error("invalid format string"));
|
||||
ulong_long precision =
|
||||
visit(internal::PrecisionHandler(), precision_arg);
|
||||
visit(internal::precision_handler(), precision_arg);
|
||||
if (precision > (std::numeric_limits<int>::max)())
|
||||
FMT_THROW(format_error("number is too big"));
|
||||
spec.precision_ = static_cast<int>(precision);
|
||||
@ -3448,7 +3417,7 @@ namespace fmt {
|
||||
namespace internal {
|
||||
|
||||
template <typename Char>
|
||||
struct UdlFormat {
|
||||
struct udl_format {
|
||||
const Char *str;
|
||||
|
||||
template <typename... Args>
|
||||
@ -3463,7 +3432,7 @@ struct UdlArg {
|
||||
const Char *str;
|
||||
|
||||
template <typename T>
|
||||
NamedArg<basic_context<Char>> operator=(T &&value) const {
|
||||
named_arg<basic_context<Char>> operator=(T &&value) const {
|
||||
return {str, std::forward<T>(value)};
|
||||
}
|
||||
};
|
||||
@ -3482,9 +3451,9 @@ inline namespace literals {
|
||||
std::string message = "The answer is {}"_format(42);
|
||||
\endrst
|
||||
*/
|
||||
inline internal::UdlFormat<char>
|
||||
inline internal::udl_format<char>
|
||||
operator"" _format(const char *s, std::size_t) { return {s}; }
|
||||
inline internal::UdlFormat<wchar_t>
|
||||
inline internal::udl_format<wchar_t>
|
||||
operator"" _format(const wchar_t *s, std::size_t) { return {s}; }
|
||||
|
||||
/**
|
||||
|
@ -49,21 +49,21 @@ class FormatBuf : public std::basic_streambuf<Char> {
|
||||
}
|
||||
};
|
||||
|
||||
Yes &convert(std::ostream &);
|
||||
yes &convert(std::ostream &);
|
||||
|
||||
struct DummyStream : std::ostream {
|
||||
DummyStream(); // Suppress a bogus warning in MSVC.
|
||||
// Hide all operator<< overloads from std::ostream.
|
||||
void operator<<(Null<>);
|
||||
void operator<<(null<>);
|
||||
};
|
||||
|
||||
No &operator<<(std::ostream &, int);
|
||||
no &operator<<(std::ostream &, int);
|
||||
|
||||
template<typename T>
|
||||
struct ConvertToIntImpl<T, true> {
|
||||
struct convert_to_int_impl<T, true> {
|
||||
// Convert to int only if T doesn't have an overloaded operator<<.
|
||||
enum {
|
||||
value = sizeof(convert(get<DummyStream>() << get<T>())) == sizeof(No)
|
||||
value = sizeof(convert(get<DummyStream>() << get<T>())) == sizeof(no)
|
||||
};
|
||||
};
|
||||
|
||||
|
28
fmt/posix.cc
28
fmt/posix.cc
@ -72,7 +72,7 @@ fmt::BufferedFile::BufferedFile(
|
||||
fmt::CStringRef filename, fmt::CStringRef mode) {
|
||||
FMT_RETRY_VAL(file_, FMT_SYSTEM(fopen(filename.c_str(), mode.c_str())), 0);
|
||||
if (!file_)
|
||||
throw SystemError(errno, "cannot open file {}", filename);
|
||||
throw system_error(errno, "cannot open file {}", filename);
|
||||
}
|
||||
|
||||
void fmt::BufferedFile::close() {
|
||||
@ -81,7 +81,7 @@ void fmt::BufferedFile::close() {
|
||||
int result = FMT_SYSTEM(fclose(file_));
|
||||
file_ = 0;
|
||||
if (result != 0)
|
||||
throw SystemError(errno, "cannot close file");
|
||||
throw system_error(errno, "cannot close file");
|
||||
}
|
||||
|
||||
// A macro used to prevent expansion of fileno on broken versions of MinGW.
|
||||
@ -90,7 +90,7 @@ void fmt::BufferedFile::close() {
|
||||
int fmt::BufferedFile::fileno() const {
|
||||
int fd = FMT_POSIX_CALL(fileno FMT_ARGS(file_));
|
||||
if (fd == -1)
|
||||
throw SystemError(errno, "cannot get file descriptor");
|
||||
throw system_error(errno, "cannot get file descriptor");
|
||||
return fd;
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ fmt::File::File(fmt::CStringRef path, int oflag) {
|
||||
FMT_RETRY(fd_, FMT_POSIX_CALL(open(path.c_str(), oflag, mode)));
|
||||
#endif
|
||||
if (fd_ == -1)
|
||||
throw SystemError(errno, "cannot open file {}", path);
|
||||
throw system_error(errno, "cannot open file {}", path);
|
||||
}
|
||||
|
||||
fmt::File::~File() FMT_NOEXCEPT {
|
||||
@ -121,7 +121,7 @@ void fmt::File::close() {
|
||||
int result = FMT_POSIX_CALL(close(fd_));
|
||||
fd_ = -1;
|
||||
if (result != 0)
|
||||
throw SystemError(errno, "cannot close file");
|
||||
throw system_error(errno, "cannot close file");
|
||||
}
|
||||
|
||||
fmt::long_long fmt::File::size() const {
|
||||
@ -135,7 +135,7 @@ fmt::long_long fmt::File::size() const {
|
||||
if (size_lower == INVALID_FILE_SIZE) {
|
||||
DWORD error = GetLastError();
|
||||
if (error != NO_ERROR)
|
||||
throw WindowsError(GetLastError(), "cannot get file size");
|
||||
throw windows_error(GetLastError(), "cannot get file size");
|
||||
}
|
||||
fmt::ulong_long long_size = size_upper;
|
||||
return (long_size << sizeof(DWORD) * CHAR_BIT) | size_lower;
|
||||
@ -143,7 +143,7 @@ fmt::long_long fmt::File::size() const {
|
||||
typedef struct stat Stat;
|
||||
Stat file_stat = Stat();
|
||||
if (FMT_POSIX_CALL(fstat(fd_, &file_stat)) == -1)
|
||||
throw SystemError(errno, "cannot get file attributes");
|
||||
throw system_error(errno, "cannot get file attributes");
|
||||
FMT_STATIC_ASSERT(sizeof(fmt::long_long) >= sizeof(file_stat.st_size),
|
||||
"return type of File::size is not large enough");
|
||||
return file_stat.st_size;
|
||||
@ -154,7 +154,7 @@ std::size_t fmt::File::read(void *buffer, std::size_t count) {
|
||||
RWResult result = 0;
|
||||
FMT_RETRY(result, FMT_POSIX_CALL(read(fd_, buffer, convert_rwcount(count))));
|
||||
if (result < 0)
|
||||
throw SystemError(errno, "cannot read from file");
|
||||
throw system_error(errno, "cannot read from file");
|
||||
return internal::to_unsigned(result);
|
||||
}
|
||||
|
||||
@ -162,7 +162,7 @@ std::size_t fmt::File::write(const void *buffer, std::size_t count) {
|
||||
RWResult result = 0;
|
||||
FMT_RETRY(result, FMT_POSIX_CALL(write(fd_, buffer, convert_rwcount(count))));
|
||||
if (result < 0)
|
||||
throw SystemError(errno, "cannot write to file");
|
||||
throw system_error(errno, "cannot write to file");
|
||||
return internal::to_unsigned(result);
|
||||
}
|
||||
|
||||
@ -171,7 +171,7 @@ fmt::File fmt::File::dup(int fd) {
|
||||
// http://pubs.opengroup.org/onlinepubs/009695399/functions/dup.html
|
||||
int new_fd = FMT_POSIX_CALL(dup(fd));
|
||||
if (new_fd == -1)
|
||||
throw SystemError(errno, "cannot duplicate file descriptor {}", fd);
|
||||
throw system_error(errno, "cannot duplicate file descriptor {}", fd);
|
||||
return File(new_fd);
|
||||
}
|
||||
|
||||
@ -179,7 +179,7 @@ void fmt::File::dup2(int fd) {
|
||||
int result = 0;
|
||||
FMT_RETRY(result, FMT_POSIX_CALL(dup2(fd_, fd)));
|
||||
if (result == -1) {
|
||||
throw SystemError(errno,
|
||||
throw system_error(errno,
|
||||
"cannot duplicate file descriptor {} to {}", fd_, fd);
|
||||
}
|
||||
}
|
||||
@ -207,7 +207,7 @@ void fmt::File::pipe(File &read_end, File &write_end) {
|
||||
int result = FMT_POSIX_CALL(pipe(fds));
|
||||
#endif
|
||||
if (result != 0)
|
||||
throw SystemError(errno, "cannot create pipe");
|
||||
throw system_error(errno, "cannot create pipe");
|
||||
// The following assignments don't throw because read_fd and write_fd
|
||||
// are closed.
|
||||
read_end = File(fds[0]);
|
||||
@ -218,7 +218,7 @@ fmt::BufferedFile fmt::File::fdopen(const char *mode) {
|
||||
// Don't retry as fdopen doesn't return EINTR.
|
||||
FILE *f = FMT_POSIX_CALL(fdopen(fd_, mode));
|
||||
if (!f)
|
||||
throw SystemError(errno, "cannot associate stream with file descriptor");
|
||||
throw system_error(errno, "cannot associate stream with file descriptor");
|
||||
BufferedFile file(f);
|
||||
fd_ = -1;
|
||||
return file;
|
||||
@ -232,7 +232,7 @@ long fmt::getpagesize() {
|
||||
#else
|
||||
long size = FMT_POSIX_CALL(sysconf(_SC_PAGESIZE));
|
||||
if (size < 0)
|
||||
throw SystemError(errno, "cannot get memory page size");
|
||||
throw system_error(errno, "cannot get memory page size");
|
||||
return size;
|
||||
#endif
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ public:
|
||||
|
||||
// A file. Closed file is represented by a File object with descriptor -1.
|
||||
// Methods that are not declared with FMT_NOEXCEPT may throw
|
||||
// fmt::SystemError in case of failure. Note that some errors such as
|
||||
// fmt::system_error in case of failure. Note that some errors such as
|
||||
// closing the file multiple times will cause a crash on Windows rather
|
||||
// than an exception. You can get standard behavior by overriding the
|
||||
// invalid parameter handler with _set_invalid_parameter_handler.
|
||||
@ -341,7 +341,7 @@ class Locale {
|
||||
|
||||
Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", NULL)) {
|
||||
if (!locale_)
|
||||
throw fmt::SystemError(errno, "cannot create locale");
|
||||
throw fmt::system_error(errno, "cannot create locale");
|
||||
}
|
||||
~Locale() { freelocale(locale_); }
|
||||
|
||||
|
@ -210,14 +210,14 @@ class PrintfWidthHandler {
|
||||
\endrst
|
||||
*/
|
||||
template <typename Char>
|
||||
class printf_arg_formatter : public internal::ArgFormatterBase<Char> {
|
||||
class printf_arg_formatter : public internal::arg_formatter_base<Char> {
|
||||
private:
|
||||
void write_null_pointer() {
|
||||
this->spec().type_ = 0;
|
||||
this->write("(nil)");
|
||||
}
|
||||
|
||||
typedef internal::ArgFormatterBase<Char> Base;
|
||||
typedef internal::arg_formatter_base<Char> Base;
|
||||
|
||||
public:
|
||||
typedef typename Base::format_specs format_specs;
|
||||
@ -230,7 +230,7 @@ class printf_arg_formatter : public internal::ArgFormatterBase<Char> {
|
||||
\endrst
|
||||
*/
|
||||
printf_arg_formatter(basic_buffer<Char> &buffer, format_specs &spec)
|
||||
: internal::ArgFormatterBase<Char>(buffer, spec) {}
|
||||
: internal::arg_formatter_base<Char>(buffer, spec) {}
|
||||
|
||||
using Base::operator();
|
||||
|
||||
|
@ -1314,7 +1314,7 @@ TEST(FormatterTest, FormatExamples) {
|
||||
EXPECT_SYSTEM_ERROR({
|
||||
FILE *f = safe_fopen(filename, "r");
|
||||
if (!f)
|
||||
throw fmt::SystemError(errno, "Cannot open file '{}'", filename);
|
||||
throw fmt::system_error(errno, "Cannot open file '{}'", filename);
|
||||
fclose(f);
|
||||
}, error_code, "Cannot open file 'nonexistent'");
|
||||
}
|
||||
@ -1514,16 +1514,16 @@ TEST(FormatTest, Enum) {
|
||||
EXPECT_EQ("0", fmt::format("{}", A));
|
||||
}
|
||||
|
||||
class MockArgFormatter : public fmt::internal::ArgFormatterBase<char> {
|
||||
class MockArgFormatter : public fmt::internal::arg_formatter_base<char> {
|
||||
private:
|
||||
MOCK_METHOD1(call, void (int value));
|
||||
|
||||
public:
|
||||
typedef fmt::internal::ArgFormatterBase<char> Base;
|
||||
typedef fmt::internal::arg_formatter_base<char> Base;
|
||||
|
||||
MockArgFormatter(fmt::buffer &b, fmt::context &ctx,
|
||||
fmt::format_specs &s)
|
||||
: fmt::internal::ArgFormatterBase<char>(b, s) {
|
||||
: fmt::internal::arg_formatter_base<char>(b, s) {
|
||||
EXPECT_CALL(*this, call(42));
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ void throw_exception() {
|
||||
}
|
||||
|
||||
void throw_system_error() {
|
||||
throw fmt::SystemError(EDOM, "test");
|
||||
throw fmt::system_error(EDOM, "test");
|
||||
}
|
||||
|
||||
// Tests that when EXPECT_THROW_MSG fails, it evaluates its message argument
|
||||
@ -207,11 +207,11 @@ TEST(ExpectThrowTest, DoesNotGenerateUnreachableCodeWarning) {
|
||||
// EXPECT_SYSTEM_ERROR macro.
|
||||
TEST(ExpectSystemErrorTest, DoesNotGenerateUnreachableCodeWarning) {
|
||||
int n = 0;
|
||||
EXPECT_SYSTEM_ERROR(throw fmt::SystemError(EDOM, "test"), EDOM, "test");
|
||||
EXPECT_SYSTEM_ERROR(throw fmt::system_error(EDOM, "test"), EDOM, "test");
|
||||
EXPECT_NONFATAL_FAILURE(EXPECT_SYSTEM_ERROR(n++, EDOM, ""), "");
|
||||
EXPECT_NONFATAL_FAILURE(EXPECT_SYSTEM_ERROR(throw 1, EDOM, ""), "");
|
||||
EXPECT_NONFATAL_FAILURE(EXPECT_SYSTEM_ERROR(
|
||||
throw fmt::SystemError(EDOM, "aaa"), EDOM, "bbb"), "");
|
||||
throw fmt::system_error(EDOM, "aaa"), EDOM, "bbb"), "");
|
||||
}
|
||||
|
||||
TEST(AssertionSyntaxTest, ExceptionAssertionBehavesLikeSingleStatement) {
|
||||
|
@ -38,7 +38,7 @@ void OutputRedirect::flush() {
|
||||
int result = 0;
|
||||
FMT_RETRY(result, fflush(file_));
|
||||
if (result != 0)
|
||||
throw fmt::SystemError(errno, "cannot flush stream");
|
||||
throw fmt::system_error(errno, "cannot flush stream");
|
||||
}
|
||||
|
||||
void OutputRedirect::restore() {
|
||||
|
@ -53,7 +53,7 @@ std::ostream &operator<<(std::ostream &os, TestEnum) {
|
||||
enum TestEnum2 {A};
|
||||
|
||||
TEST(OStreamTest, Enum) {
|
||||
EXPECT_FALSE(fmt::internal::ConvertToInt<TestEnum>::value);
|
||||
EXPECT_FALSE(fmt::internal::convert_to_int<TestEnum>::value);
|
||||
EXPECT_EQ("TestEnum", fmt::format("{}", TestEnum()));
|
||||
EXPECT_EQ("0", fmt::format("{}", A));
|
||||
}
|
||||
|
@ -415,7 +415,7 @@ TEST(BufferedFileTest, OpenRetry) {
|
||||
#ifndef _WIN32
|
||||
char c = 0;
|
||||
if (fread(&c, 1, 1, f->get()) < 1)
|
||||
throw fmt::SystemError(errno, "fread failed");
|
||||
throw fmt::system_error(errno, "fread failed");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,7 @@ TEST(BufferedFileTest, Fileno) {
|
||||
EXPECT_DEATH_IF_SUPPORTED({
|
||||
try {
|
||||
f.fileno();
|
||||
} catch (fmt::SystemError) {
|
||||
} catch (fmt::system_error) {
|
||||
std::exit(1);
|
||||
}
|
||||
}, "");
|
||||
|
@ -652,7 +652,7 @@ TEST(UtilTest, CountDigits) {
|
||||
#ifdef _WIN32
|
||||
TEST(UtilTest, UTF16ToUTF8) {
|
||||
std::string s = "ёжик";
|
||||
fmt::internal::UTF16ToUTF8 u(L"\x0451\x0436\x0438\x043A");
|
||||
fmt::internal::utf16_to_utf8 u(L"\x0451\x0436\x0438\x043A");
|
||||
EXPECT_EQ(s, u.str());
|
||||
EXPECT_EQ(s.size(), u.size());
|
||||
}
|
||||
@ -681,7 +681,7 @@ void check_utf_conversion_error(
|
||||
}
|
||||
|
||||
TEST(UtilTest, UTF16ToUTF8Error) {
|
||||
check_utf_conversion_error<fmt::internal::UTF16ToUTF8, wchar_t>(
|
||||
check_utf_conversion_error<fmt::internal::utf16_to_utf8, wchar_t>(
|
||||
"cannot convert string from UTF-16 to UTF-8");
|
||||
}
|
||||
|
||||
@ -693,7 +693,7 @@ TEST(UtilTest, UTF8ToUTF16Error) {
|
||||
}
|
||||
|
||||
TEST(UtilTest, UTF16ToUTF8Convert) {
|
||||
fmt::internal::UTF16ToUTF8 u;
|
||||
fmt::internal::utf16_to_utf8 u;
|
||||
EXPECT_EQ(ERROR_INVALID_PARAMETER, u.convert(fmt::wstring_view(0, 0)));
|
||||
EXPECT_EQ(ERROR_INVALID_PARAMETER,
|
||||
u.convert(fmt::wstring_view(L"foo", INT_MAX + 1u)));
|
||||
@ -705,10 +705,10 @@ typedef void (*FormatErrorMessage)(
|
||||
|
||||
template <typename Error>
|
||||
void check_throw_error(int error_code, FormatErrorMessage format) {
|
||||
fmt::SystemError error(0, "");
|
||||
fmt::system_error error(0, "");
|
||||
try {
|
||||
throw Error(error_code, "test {}", "error");
|
||||
} catch (const fmt::SystemError &e) {
|
||||
} catch (const fmt::system_error &e) {
|
||||
error = e;
|
||||
}
|
||||
fmt::memory_buffer message;
|
||||
@ -729,10 +729,10 @@ TEST(UtilTest, FormatSystemError) {
|
||||
}
|
||||
|
||||
TEST(UtilTest, SystemError) {
|
||||
fmt::SystemError e(EDOM, "test");
|
||||
fmt::system_error e(EDOM, "test");
|
||||
EXPECT_EQ(fmt::format("test: {}", get_system_error(EDOM)), e.what());
|
||||
EXPECT_EQ(EDOM, e.error_code());
|
||||
check_throw_error<fmt::SystemError>(EDOM, fmt::format_system_error);
|
||||
check_throw_error<fmt::system_error>(EDOM, fmt::format_system_error);
|
||||
}
|
||||
|
||||
TEST(UtilTest, ReportSystemError) {
|
||||
@ -751,7 +751,7 @@ TEST(UtilTest, FormatWindowsError) {
|
||||
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0,
|
||||
ERROR_FILE_EXISTS, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
reinterpret_cast<LPWSTR>(&message), 0, 0);
|
||||
fmt::internal::UTF16ToUTF8 utf8_message(message);
|
||||
fmt::internal::utf16_to_utf8 utf8_message(message);
|
||||
LocalFree(message);
|
||||
fmt::memory_buffer actual_message;
|
||||
fmt::internal::format_windows_error(
|
||||
@ -778,7 +778,7 @@ TEST(UtilTest, FormatLongWindowsError) {
|
||||
reinterpret_cast<LPWSTR>(&message), 0, 0) == 0) {
|
||||
return;
|
||||
}
|
||||
fmt::internal::UTF16ToUTF8 utf8_message(message);
|
||||
fmt::internal::utf16_to_utf8 utf8_message(message);
|
||||
LocalFree(message);
|
||||
fmt::memory_buffer actual_message;
|
||||
fmt::internal::format_windows_error(
|
||||
@ -806,15 +806,15 @@ TEST(UtilTest, ReportWindowsError) {
|
||||
enum TestEnum2 {};
|
||||
|
||||
TEST(UtilTest, ConvertToInt) {
|
||||
EXPECT_TRUE(fmt::internal::ConvertToInt<char>::enable_conversion);
|
||||
EXPECT_FALSE(fmt::internal::ConvertToInt<const char *>::enable_conversion);
|
||||
EXPECT_TRUE(fmt::internal::ConvertToInt<TestEnum2>::value);
|
||||
EXPECT_TRUE(fmt::internal::convert_to_int<char>::enable_conversion);
|
||||
EXPECT_FALSE(fmt::internal::convert_to_int<const char *>::enable_conversion);
|
||||
EXPECT_TRUE(fmt::internal::convert_to_int<TestEnum2>::value);
|
||||
}
|
||||
|
||||
#if FMT_USE_ENUM_BASE
|
||||
enum TestEnum : char {TestValue};
|
||||
TEST(UtilTest, IsEnumConvertibleToInt) {
|
||||
EXPECT_TRUE(fmt::internal::ConvertToInt<TestEnum>::enable_conversion);
|
||||
EXPECT_TRUE(fmt::internal::convert_to_int<TestEnum>::enable_conversion);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user