From c333dca065d98e9ca75c3f4cd645835ba670b9bf Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 19 Feb 2017 08:41:38 -0800 Subject: [PATCH] Follow standard naming conventions --- fmt/format.cc | 37 +++--- fmt/format.h | 259 +++++++++++++++++---------------------- fmt/ostream.h | 10 +- fmt/posix.cc | 28 ++--- fmt/posix.h | 4 +- fmt/printf.h | 6 +- test/format-test.cc | 8 +- test/gtest-extra-test.cc | 6 +- test/gtest-extra.cc | 2 +- test/ostream-test.cc | 2 +- test/posix-mock-test.cc | 2 +- test/posix-test.cc | 2 +- test/util-test.cc | 26 ++-- 13 files changed, 180 insertions(+), 212 deletions(-) diff --git a/fmt/format.cc b/fmt/format.cc index b4a8f078..d1a449d6 100644 --- a/fmt/format.cc +++ b/fmt/format.cc @@ -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(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(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(buffer.size()), 0); if (result != 0) { - UTF16ToUTF8 utf8_message; + utf16_to_utf8 utf8_message; if (utf8_message.convert(system_message) == ERROR_SUCCESS) { basic_writer w(out); w.write(message); @@ -459,7 +458,7 @@ template struct internal::basic_data; template void basic_fixed_buffer::grow(std::size_t); -template void internal::ArgMap::init(const args &args); +template void internal::arg_map::init(const args &args); template void printf_context::format(buffer &); @@ -477,7 +476,7 @@ template class basic_context; template void basic_fixed_buffer::grow(std::size_t); -template void internal::ArgMap::init(const wargs &args); +template void internal::arg_map::init(const wargs &args); template void printf_context::format(wbuffer &); diff --git a/fmt/format.h b/fmt/format.h index eea1b83e..b4b41fbd 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -555,7 +555,7 @@ inline typename make_unsigned::type to_unsigned(Int value) { return static_cast::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 -struct Null {}; +struct null {}; // A helper class template to enable or disable overloads taking wide // characters and strings in value's constructor. template -struct WCharHelper { - typedef Null Supported; - typedef T Unsupported; +struct wchar_helper { + typedef null supported; + typedef T unsupported; }; template -struct WCharHelper { - typedef T Supported; - typedef Null Unsupported; +struct wchar_helper { + typedef T supported; + typedef null unsupported; }; -typedef char Yes[1]; -typedef char No[2]; +typedef char yes[1]; +typedef char no[2]; template 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 -struct ConvertToIntImpl { +struct convert_to_int_impl { enum { value = ENABLE_CONVERSION }; }; template -struct ConvertToIntImpl2 { +struct convert_to_int_impl2 { enum { value = false }; }; template -struct ConvertToIntImpl2 { +struct convert_to_int_impl2 { enum { // Don't convert numeric types. - value = ConvertToIntImpl::is_specialized>::value + value = convert_to_int_impl< + T, !std::numeric_limits::is_specialized>::value }; }; template -struct ConvertToInt { - enum { enable_conversion = sizeof(convert(get())) == sizeof(Yes) }; - enum { value = ConvertToIntImpl2::value }; +struct convert_to_int { + enum { enable_conversion = sizeof(convert(get())) == sizeof(yes) }; + enum { value = convert_to_int_impl2::value }; }; #define FMT_DISABLE_CONVERSION_TO_INT(Type) \ template <> \ - struct ConvertToInt { enum { value = 0 }; } + struct convert_to_int { enum { value = 0 }; } // Silence warnings about convering float to int. FMT_DISABLE_CONVERSION_TO_INT(float); @@ -1141,18 +1141,18 @@ struct custom_value { }; template -struct NamedArg; +struct named_arg; template -struct IsNamedArg : std::false_type {}; +struct is_named_arg : std::false_type {}; template -struct IsNamedArg< NamedArg > : std::true_type {}; +struct is_named_arg< named_arg > : std::true_type {}; template constexpr Type gettype() { - return IsNamedArg::value ? - NAMED_ARG : (ConvertToInt::value ? INT : CUSTOM); + return is_named_arg::value ? + NAMED_ARG : (convert_to_int::value ? INT : CUSTOM); } template <> constexpr Type gettype() { 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::Unsupported); + value(typename wchar_helper::unsupported); #endif - value(typename WCharHelper::Unsupported); - value(typename WCharHelper::Unsupported); - value(typename WCharHelper::Unsupported); - value(typename WCharHelper::Unsupported); + value(typename wchar_helper::unsupported); + value(typename wchar_helper::unsupported); + value(typename wchar_helper::unsupported); + value(typename wchar_helper::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::Supported WChar; + typedef typename wchar_helper::supported WChar; value(WChar value) { static_assert(internal::type() == 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::Supported value) { \ + value(typename wchar_helper::supported value) { \ static_assert(internal::type() == internal::TYPE, "invalid type"); \ set_string(value); \ } @@ -1344,7 +1344,7 @@ class value { template value(const T &value, - typename enable_if::value, int>::type = 0) { + typename enable_if::value, int>::type = 0) { static_assert(internal::type() == internal::CUSTOM, "invalid type"); this->custom.value = &value; this->custom.format = &format_custom_arg; @@ -1352,7 +1352,7 @@ class value { template value(const T &value, - typename enable_if::value, int>::type = 0) { + typename enable_if::value, int>::type = 0) { static_assert(internal::type() == 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 - value(const NamedArg &value) { + value(const named_arg &value) { static_assert( - internal::type &>() == internal::NAMED_ARG, + internal::type &>() == internal::NAMED_ARG, "invalid type"); this->pointer = &value; } }; template -class ArgMap; +class arg_map; template basic_arg make_arg(const T &value); @@ -1381,7 +1381,7 @@ template 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 class basic_arg { private: @@ -1396,7 +1396,7 @@ class basic_arg { visit(Visitor &&vis, basic_arg arg); friend class basic_args; - friend class internal::ArgMap; + friend class internal::arg_map; public: basic_arg() : type_(internal::NONE) {} @@ -1476,8 +1476,8 @@ basic_arg make_arg(const T &value) { return arg; } -template struct LConvCheck { - LConvCheck(int) {} +template struct lconv_check { + lconv_check(int) {} }; // Returns the thousands separator for the current locale. @@ -1485,7 +1485,7 @@ template struct LConvCheck { // ``lconv`` is stubbed as an empty struct. template inline string_view thousands_sep( - LConv *lc, LConvCheck = 0) { + LConv *lc, lconv_check = 0) { return lc->thousands_sep; } @@ -1521,22 +1521,16 @@ void format_value(basic_buffer &, const T &, Formatter &, const Char *) { } template -struct NamedArg : basic_arg { +struct named_arg : basic_arg { typedef typename Context::char_type Char; basic_string_view name; template - NamedArg(basic_string_view argname, const T &value) + named_arg(basic_string_view argname, const T &value) : basic_arg(make_arg(value)), name(argname) {} }; -class RuntimeError : public std::runtime_error { - protected: - RuntimeError() : std::runtime_error("") {} - ~RuntimeError() throw(); -}; - template constexpr uint64_t make_type() { return type() | (make_type() << 4); @@ -1625,7 +1619,7 @@ class basic_args { (types_ & (mask << shift)) >> shift); } - friend class internal::ArgMap; + friend class internal::arg_map; void set_data(const internal::value *values) { values_ = values; } void set_data(const format_arg *args) { args_ = args; } @@ -1674,7 +1668,7 @@ class basic_args { typedef basic_args args; typedef basic_args wargs; -enum Alignment { +enum alignment { ALIGN_DEFAULT, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_NUMERIC }; @@ -1736,53 +1730,26 @@ constexpr format_spec_factory width; constexpr format_spec_factory type; // An empty format specifier. -struct EmptySpec {}; +struct empty_spec {}; -// A type specifier. -template -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 -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 class basic_format_specs : public AlignSpec { @@ -1832,7 +1799,7 @@ typedef basic_format_specs format_specs; namespace internal { template -class ArgMap { +class arg_map { private: typedef typename Context::char_type Char; typedef std::vector< @@ -1857,10 +1824,10 @@ class ArgMap { }; template -void ArgMap::init(const basic_args &args) { +void arg_map::init(const basic_args &args) { if (!map_.empty()) return; - typedef internal::NamedArg NamedArg; + typedef internal::named_arg NamedArg; const NamedArg *named_arg = 0; bool use_values = args.type(MAX_PACKED_ARGS - 1) == internal::NONE; @@ -1902,7 +1869,7 @@ void ArgMap::init(const basic_args &args) { } template -class ArgFormatterBase { +class arg_formatter_base { public: typedef basic_format_specs format_specs; @@ -1910,7 +1877,7 @@ class ArgFormatterBase { basic_writer 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 &b, format_specs &s) + arg_formatter_base(basic_buffer &b, format_specs &s) : writer_(b), spec_(s) {} void operator()(monostate) { @@ -2078,11 +2045,11 @@ class context_base { /** The default argument formatter. */ template -class arg_formatter : public internal::ArgFormatterBase { +class arg_formatter : public internal::arg_formatter_base { private: basic_context &ctx_; - typedef internal::ArgFormatterBase Base; + typedef internal::arg_formatter_base Base; public: typedef typename Base::format_specs format_specs; @@ -2097,9 +2064,9 @@ class arg_formatter : public internal::ArgFormatterBase { */ arg_formatter(basic_buffer &buffer, basic_context &ctx, format_specs &spec) - : internal::ArgFormatterBase(buffer, spec), ctx_(ctx) {} + : internal::arg_formatter_base(buffer, spec), ctx_(ctx) {} - using internal::ArgFormatterBase::operator(); + using internal::arg_formatter_base::operator(); /** Formats an argument of a custom (user-defined) type. */ void operator()(internal::custom_value c) { @@ -2115,7 +2082,7 @@ class basic_context : typedef Char char_type; private: - internal::ArgMap> map_; + internal::arg_map> 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 - 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::Unsupported); + void operator<<(typename internal::wchar_helper::unsupported); void operator<<( - typename internal::WCharHelper::Unsupported); + typename internal::wchar_helper::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 - friend class internal::ArgFormatterBase; + friend class internal::arg_formatter_base; template friend class printf_arg_formatter; @@ -2427,7 +2395,7 @@ class basic_writer { buffer_.push_back(value); } - void write(typename internal::WCharHelper::Supported value) { + void write(typename internal::wchar_helper::supported value) { buffer_.push_back(value); } @@ -2442,7 +2410,7 @@ class basic_writer { } void write( - typename internal::WCharHelper::Supported value) { + typename internal::wchar_helper::supported value) { const char *str = value.data(); buffer_.append(str, str + value.size()); } @@ -2522,7 +2490,7 @@ typename basic_writer::CharPtr basic_writer::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::cast(spec.fill()); if (spec.precision() > static_cast(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 - 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 -inline internal::NamedArg arg(string_view name, const T &arg) { - return internal::NamedArg(name, arg); +inline internal::named_arg arg(string_view name, const T &arg) { + return internal::named_arg(name, arg); } template -inline internal::NamedArg arg(wstring_view name, const T &arg) { - return internal::NamedArg(name, arg); +inline internal::named_arg arg(wstring_view name, const T &arg) { + return internal::named_arg(name, arg); } // The following two functions are deleted intentionally to disable // nested named arguments as in ``format("{}", arg("a", arg("b", 42)))``. template -void arg(string_view, const internal::NamedArg&) +void arg(string_view, const internal::named_arg&) FMT_DELETED_OR_UNDEFINED; template -void arg(wstring_view, const internal::NamedArg&) +void arg(wstring_view, const internal::named_arg&) 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 std::enable_if::value, bool>::type operator()(T value) { @@ -3181,7 +3150,7 @@ template void check_sign(const Char *&s, const basic_arg &arg) { char sign = static_cast(*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 &arg) { } template -class CustomFormatter { +class custom_formatter { private: basic_buffer &buffer_; Context &ctx_; public: - CustomFormatter(basic_buffer &buffer, Context &ctx) + custom_formatter(basic_buffer &buffer, Context &ctx) : buffer_(buffer), ctx_(ctx) {} bool operator()(internal::custom_value custom) { @@ -3208,16 +3177,16 @@ class CustomFormatter { }; template -struct IsInteger { +struct is_integer { enum { value = std::is_integral::value && !std::is_same::value && !std::is_same::value && !std::is_same::value }; }; -struct WidthHandler { +struct width_handler { template - typename std::enable_if::value, ulong_long>::type + typename std::enable_if::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 std::enable_if::value, ulong_long>::type + typename std::enable_if::value, ulong_long>::type operator()(T value) { FMT_THROW(format_error("width is not integer")); return 0; } }; -struct PrecisionHandler { +struct precision_handler { template - typename std::enable_if::value, ulong_long>::type + typename std::enable_if::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 std::enable_if::value, ulong_long>::type + typename std::enable_if::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 &buffer, basic_arg arg, const Char *&s = ctx.ptr(); basic_format_specs spec; if (*s == ':') { - if (visit(internal::CustomFormatter(buffer, ctx), arg)) + if (visit(internal::custom_formatter(buffer, ctx), arg)) return; ++s; // Parse fill and alignment. @@ -3372,7 +3341,7 @@ void do_format_arg(basic_buffer &buffer, basic_arg 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::max)()) FMT_THROW(format_error("number is too big")); spec.width_ = static_cast(width); @@ -3390,7 +3359,7 @@ void do_format_arg(basic_buffer &buffer, basic_arg 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::max)()) FMT_THROW(format_error("number is too big")); spec.precision_ = static_cast(precision); @@ -3448,7 +3417,7 @@ namespace fmt { namespace internal { template -struct UdlFormat { +struct udl_format { const Char *str; template @@ -3463,7 +3432,7 @@ struct UdlArg { const Char *str; template - NamedArg> operator=(T &&value) const { + named_arg> operator=(T &&value) const { return {str, std::forward(value)}; } }; @@ -3482,9 +3451,9 @@ inline namespace literals { std::string message = "The answer is {}"_format(42); \endrst */ -inline internal::UdlFormat +inline internal::udl_format operator"" _format(const char *s, std::size_t) { return {s}; } -inline internal::UdlFormat +inline internal::udl_format operator"" _format(const wchar_t *s, std::size_t) { return {s}; } /** diff --git a/fmt/ostream.h b/fmt/ostream.h index 8672ac6c..59ccc83e 100644 --- a/fmt/ostream.h +++ b/fmt/ostream.h @@ -49,21 +49,21 @@ class FormatBuf : public std::basic_streambuf { } }; -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 -struct ConvertToIntImpl { +struct convert_to_int_impl { // Convert to int only if T doesn't have an overloaded operator<<. enum { - value = sizeof(convert(get() << get())) == sizeof(No) + value = sizeof(convert(get() << get())) == sizeof(no) }; }; diff --git a/fmt/posix.cc b/fmt/posix.cc index 260f6341..f8ce6b9e 100644 --- a/fmt/posix.cc +++ b/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 } diff --git a/fmt/posix.h b/fmt/posix.h index 45cf3c7c..03cbc664 100644 --- a/fmt/posix.h +++ b/fmt/posix.h @@ -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_); } diff --git a/fmt/printf.h b/fmt/printf.h index c77100a8..88a5450c 100644 --- a/fmt/printf.h +++ b/fmt/printf.h @@ -210,14 +210,14 @@ class PrintfWidthHandler { \endrst */ template -class printf_arg_formatter : public internal::ArgFormatterBase { +class printf_arg_formatter : public internal::arg_formatter_base { private: void write_null_pointer() { this->spec().type_ = 0; this->write("(nil)"); } - typedef internal::ArgFormatterBase Base; + typedef internal::arg_formatter_base Base; public: typedef typename Base::format_specs format_specs; @@ -230,7 +230,7 @@ class printf_arg_formatter : public internal::ArgFormatterBase { \endrst */ printf_arg_formatter(basic_buffer &buffer, format_specs &spec) - : internal::ArgFormatterBase(buffer, spec) {} + : internal::arg_formatter_base(buffer, spec) {} using Base::operator(); diff --git a/test/format-test.cc b/test/format-test.cc index 14b95361..66397856 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -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 { +class MockArgFormatter : public fmt::internal::arg_formatter_base { private: MOCK_METHOD1(call, void (int value)); public: - typedef fmt::internal::ArgFormatterBase Base; + typedef fmt::internal::arg_formatter_base Base; MockArgFormatter(fmt::buffer &b, fmt::context &ctx, fmt::format_specs &s) - : fmt::internal::ArgFormatterBase(b, s) { + : fmt::internal::arg_formatter_base(b, s) { EXPECT_CALL(*this, call(42)); } diff --git a/test/gtest-extra-test.cc b/test/gtest-extra-test.cc index 97c4bee1..ac11cf94 100644 --- a/test/gtest-extra-test.cc +++ b/test/gtest-extra-test.cc @@ -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) { diff --git a/test/gtest-extra.cc b/test/gtest-extra.cc index 34daf4db..307bd84d 100644 --- a/test/gtest-extra.cc +++ b/test/gtest-extra.cc @@ -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() { diff --git a/test/ostream-test.cc b/test/ostream-test.cc index fd40a2a1..a3cc4ddb 100644 --- a/test/ostream-test.cc +++ b/test/ostream-test.cc @@ -53,7 +53,7 @@ std::ostream &operator<<(std::ostream &os, TestEnum) { enum TestEnum2 {A}; TEST(OStreamTest, Enum) { - EXPECT_FALSE(fmt::internal::ConvertToInt::value); + EXPECT_FALSE(fmt::internal::convert_to_int::value); EXPECT_EQ("TestEnum", fmt::format("{}", TestEnum())); EXPECT_EQ("0", fmt::format("{}", A)); } diff --git a/test/posix-mock-test.cc b/test/posix-mock-test.cc index 5a337b6e..69f44567 100644 --- a/test/posix-mock-test.cc +++ b/test/posix-mock-test.cc @@ -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 } diff --git a/test/posix-test.cc b/test/posix-test.cc index c4b6f4dd..a0b2c90d 100644 --- a/test/posix-test.cc +++ b/test/posix-test.cc @@ -173,7 +173,7 @@ TEST(BufferedFileTest, Fileno) { EXPECT_DEATH_IF_SUPPORTED({ try { f.fileno(); - } catch (fmt::SystemError) { + } catch (fmt::system_error) { std::exit(1); } }, ""); diff --git a/test/util-test.cc b/test/util-test.cc index 387203e5..19e960f1 100644 --- a/test/util-test.cc +++ b/test/util-test.cc @@ -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( + check_utf_conversion_error( "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 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(EDOM, fmt::format_system_error); + check_throw_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(&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(&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::enable_conversion); - EXPECT_FALSE(fmt::internal::ConvertToInt::enable_conversion); - EXPECT_TRUE(fmt::internal::ConvertToInt::value); + EXPECT_TRUE(fmt::internal::convert_to_int::enable_conversion); + EXPECT_FALSE(fmt::internal::convert_to_int::enable_conversion); + EXPECT_TRUE(fmt::internal::convert_to_int::value); } #if FMT_USE_ENUM_BASE enum TestEnum : char {TestValue}; TEST(UtilTest, IsEnumConvertibleToInt) { - EXPECT_TRUE(fmt::internal::ConvertToInt::enable_conversion); + EXPECT_TRUE(fmt::internal::convert_to_int::enable_conversion); } #endif