Follow standard naming conventions

This commit is contained in:
Victor Zverovich 2017-02-19 06:46:51 -08:00
parent eedfd07f8b
commit 6a2ff287b2
9 changed files with 143 additions and 156 deletions

View File

@ -186,8 +186,8 @@ void format_error_code(buffer &out, int error_code,
static const char ERROR_STR[] = "error ";
// Subtract 2 to account for terminating null characters in SEP and ERROR_STR.
std::size_t error_code_size = sizeof(SEP) + sizeof(ERROR_STR) - 2;
typedef internal::IntTraits<int>::MainType MainType;
MainType abs_value = static_cast<MainType>(error_code);
typedef internal::int_traits<int>::main_type main_type;
main_type abs_value = static_cast<main_type>(error_code);
if (internal::is_negative(error_code)) {
abs_value = 0 - abs_value;
++error_code_size;
@ -224,7 +224,7 @@ FMT_FUNC void SystemError::init(
}
template <typename T>
int internal::CharTraits<char>::format_float(
int internal::char_traits<char>::format_float(
char *buffer, std::size_t size, const char *format,
unsigned width, int precision, T value) {
if (width == 0) {
@ -238,7 +238,7 @@ int internal::CharTraits<char>::format_float(
}
template <typename T>
int internal::CharTraits<wchar_t>::format_float(
int internal::char_traits<wchar_t>::format_float(
wchar_t *buffer, std::size_t size, const wchar_t *format,
unsigned width, int precision, T value) {
if (width == 0) {
@ -252,7 +252,7 @@ int internal::CharTraits<wchar_t>::format_float(
}
template <typename T>
const char internal::BasicData<T>::DIGITS[] =
const char internal::basic_data<T>::DIGITS[] =
"0001020304050607080910111213141516171819"
"2021222324252627282930313233343536373839"
"4041424344454647484950515253545556575859"
@ -271,12 +271,12 @@ const char internal::BasicData<T>::DIGITS[] =
factor * 1000000000
template <typename T>
const uint32_t internal::BasicData<T>::POWERS_OF_10_32[] = {
const uint32_t internal::basic_data<T>::POWERS_OF_10_32[] = {
0, FMT_POWERS_OF_10(1)
};
template <typename T>
const uint64_t internal::BasicData<T>::POWERS_OF_10_64[] = {
const uint64_t internal::basic_data<T>::POWERS_OF_10_64[] = {
0,
FMT_POWERS_OF_10(1),
FMT_POWERS_OF_10(ulong_long(1000000000)),
@ -298,7 +298,7 @@ FMT_FUNC void internal::report_unknown_type(char code, const char *type) {
#if FMT_USE_WINDOWS_H
FMT_FUNC internal::UTF8ToUTF16::UTF8ToUTF16(string_view s) {
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));
@ -341,7 +341,7 @@ FMT_FUNC int internal::UTF16ToUTF8::convert(wstring_view s) {
FMT_FUNC void WindowsError::init(
int err_code, CStringRef format_str, args args) {
error_code_ = err_code;
internal::MemoryBuffer<char> buffer;
memory_buffer buffer;
internal::format_windows_error(buffer, err_code, vformat(format_str, args));
std::runtime_error &base = *this;
base = std::runtime_error(to_string(buffer));
@ -350,7 +350,7 @@ FMT_FUNC void WindowsError::init(
FMT_FUNC void internal::format_windows_error(
buffer &out, int error_code, string_view message) FMT_NOEXCEPT {
FMT_TRY {
MemoryBuffer<wchar_t> buffer;
wmemory_buffer buffer;
buffer.resize(INLINE_BUFFER_SIZE);
for (;;) {
wchar_t *system_message = &buffer[0];
@ -403,7 +403,7 @@ FMT_FUNC void format_system_error(
}
template <typename Char>
void FixedBuffer<Char>::grow(std::size_t) {
void basic_fixed_buffer<Char>::grow(std::size_t) {
FMT_THROW(std::runtime_error("buffer overflow"));
}
@ -453,21 +453,21 @@ FMT_FUNC int vfprintf(std::FILE *f, CStringRef format, printf_args args) {
#ifndef FMT_HEADER_ONLY
template struct internal::BasicData<void>;
template struct internal::basic_data<void>;
// Explicit instantiations for char.
template void FixedBuffer<char>::grow(std::size_t);
template void basic_fixed_buffer<char>::grow(std::size_t);
template void internal::ArgMap<context>::init(const args &args);
template void printf_context<char>::format(buffer &);
template int internal::CharTraits<char>::format_float(
template int internal::char_traits<char>::format_float(
char *buffer, std::size_t size, const char *format,
unsigned width, int precision, double value);
template int internal::CharTraits<char>::format_float(
template int internal::char_traits<char>::format_float(
char *buffer, std::size_t size, const char *format,
unsigned width, int precision, long double value);
@ -475,17 +475,17 @@ template int internal::CharTraits<char>::format_float(
template class basic_context<wchar_t>;
template void FixedBuffer<wchar_t>::grow(std::size_t);
template void basic_fixed_buffer<wchar_t>::grow(std::size_t);
template void internal::ArgMap<wcontext>::init(const wargs &args);
template void printf_context<wchar_t>::format(wbuffer &);
template int internal::CharTraits<wchar_t>::format_float(
template int internal::char_traits<wchar_t>::format_float(
wchar_t *buffer, std::size_t size, const wchar_t *format,
unsigned width, int precision, double value);
template int internal::CharTraits<wchar_t>::format_float(
template int internal::char_traits<wchar_t>::format_float(
wchar_t *buffer, std::size_t size, const wchar_t *format,
unsigned width, int precision, long double value);

View File

@ -532,13 +532,14 @@ class format_error : public std::runtime_error {
namespace internal {
// MakeUnsigned<T>::Type gives an unsigned type corresponding to integer type T.
// make_unsigned<T>::type gives an unsigned type corresponding to integer
// type T.
template <typename T>
struct MakeUnsigned { typedef T Type; };
struct make_unsigned { typedef T type; };
#define FMT_SPECIALIZE_MAKE_UNSIGNED(T, U) \
template <> \
struct MakeUnsigned<T> { typedef U Type; }
struct make_unsigned<T> { typedef U type; }
FMT_SPECIALIZE_MAKE_UNSIGNED(char, unsigned char);
FMT_SPECIALIZE_MAKE_UNSIGNED(signed char, unsigned char);
@ -549,9 +550,9 @@ FMT_SPECIALIZE_MAKE_UNSIGNED(long_long, ulong_long);
// Casts nonnegative integer to unsigned.
template <typename Int>
inline typename MakeUnsigned<Int>::Type to_unsigned(Int value) {
inline typename make_unsigned<Int>::type to_unsigned(Int value) {
FMT_ASSERT(value >= 0, "negative value");
return static_cast<typename MakeUnsigned<Int>::Type>(value);
return static_cast<typename make_unsigned<Int>::type>(value);
}
// The number of characters to store in the MemoryBuffer object itself
@ -789,25 +790,26 @@ typedef basic_memory_buffer<wchar_t> wmemory_buffer;
\endrst
*/
template <typename Char>
class FixedBuffer : public basic_buffer<Char> {
class basic_fixed_buffer : public basic_buffer<Char> {
public:
/**
\rst
Constructs a :class:`fmt::FixedBuffer` object for *array* of the
Constructs a :class:`fmt::basic_fixed_buffer` object for *array* of the
given size.
\endrst
*/
FixedBuffer(Char *array, std::size_t size)
basic_fixed_buffer(Char *array, std::size_t size)
: basic_buffer<Char>(array, size) {}
/**
\rst
Constructs a :class:`fmt::FixedBuffer` object for *array* of the
Constructs a :class:`fmt::basic_fixed_buffer` object for *array* of the
size known at compile time.
\endrst
*/
template <std::size_t SIZE>
explicit FixedBuffer(Char (&array)[SIZE]) : basic_buffer<Char>(array, SIZE) {}
explicit basic_fixed_buffer(Char (&array)[SIZE])
: basic_buffer<Char>(array, SIZE) {}
protected:
FMT_API void grow(std::size_t size);
@ -816,7 +818,7 @@ class FixedBuffer : public basic_buffer<Char> {
namespace internal {
template <typename Char>
class BasicCharTraits {
class basic_char_traits {
public:
#if FMT_SECURE_SCL
typedef stdext::checked_array_iterator<Char*> CharPtr;
@ -827,10 +829,10 @@ class BasicCharTraits {
};
template <typename Char>
class CharTraits;
class char_traits;
template <>
class CharTraits<char> : public BasicCharTraits<char> {
class char_traits<char> : public basic_char_traits<char> {
private:
// Conversion from wchar_t to char is not allowed.
static char convert(wchar_t);
@ -845,7 +847,7 @@ class CharTraits<char> : public BasicCharTraits<char> {
};
template <>
class CharTraits<wchar_t> : public BasicCharTraits<wchar_t> {
class char_traits<wchar_t> : public basic_char_traits<wchar_t> {
public:
static wchar_t convert(char value) { return value; }
static wchar_t convert(wchar_t value) { return value; }
@ -855,39 +857,37 @@ class CharTraits<wchar_t> : public BasicCharTraits<wchar_t> {
const wchar_t *format, unsigned width, int precision, T value);
};
// Checks if a number is negative - used to avoid warnings.
template <bool IsSigned>
struct SignChecker {
template <typename T>
static bool is_negative(T value) { return value < 0; }
};
template <bool B, class T = void>
struct enable_if {};
template <>
struct SignChecker<false> {
template <typename T>
static bool is_negative(T) { return false; }
};
template <class T>
struct enable_if<true, T> { typedef T type; };
template <bool B, class T, class F>
struct conditional { typedef T type; };
template<class T, class F>
struct conditional<false, T, F> { typedef F type; };
// Returns true if value is negative, false otherwise.
// Same as (value < 0) but doesn't produce warnings if T is an unsigned type.
template <typename T>
inline bool is_negative(T value) {
return SignChecker<std::numeric_limits<T>::is_signed>::is_negative(value);
inline typename enable_if<std::numeric_limits<T>::is_signed, bool>::type
is_negative(T value) {
return value < 0;
}
template <typename T>
inline typename enable_if<!std::numeric_limits<T>::is_signed, bool>::type
is_negative(T) {
return false;
}
// Selects uint32_t if FitsIn32Bits is true, uint64_t otherwise.
template <bool FitsIn32Bits>
struct TypeSelector { typedef uint32_t Type; };
template <>
struct TypeSelector<false> { typedef uint64_t Type; };
template <typename T>
struct IntTraits {
struct int_traits {
// Smallest of uint32_t and uint64_t that is large enough to represent
// all values of T.
typedef typename
TypeSelector<std::numeric_limits<T>::digits <= 32>::Type MainType;
typedef typename conditional<
std::numeric_limits<T>::digits <= 32, uint32_t, uint64_t>::type main_type;
};
FMT_API void report_unknown_type(char code, const char *type);
@ -895,7 +895,7 @@ FMT_API void report_unknown_type(char code, const char *type);
// Static data is placed in this class template to allow header-only
// configuration.
template <typename T = void>
struct FMT_API BasicData {
struct FMT_API basic_data {
static const uint32_t POWERS_OF_10_32[];
static const uint64_t POWERS_OF_10_64[];
static const char DIGITS[];
@ -908,10 +908,10 @@ struct FMT_API BasicData {
#endif
#if FMT_USE_EXTERN_TEMPLATES && !defined(FMT_HEADER_ONLY)
extern template struct BasicData<void>;
extern template struct basic_data<void>;
#endif
typedef BasicData<> Data;
typedef basic_data<> data;
#ifdef FMT_BUILTIN_CLZLL
// Returns the number of decimal digits in n. Leading zeros are not counted
@ -920,7 +920,7 @@ inline unsigned count_digits(uint64_t n) {
// Based on http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10
// and the benchmark https://github.com/localvoid/cxx-benchmark-count-digits.
int t = (64 - FMT_BUILTIN_CLZLL(n | 1)) * 1233 >> 12;
return to_unsigned(t) - (n < Data::POWERS_OF_10_64[t]) + 1;
return to_unsigned(t) - (n < data::POWERS_OF_10_64[t]) + 1;
}
#else
// Fallback version of count_digits used when __builtin_clz is not available.
@ -944,18 +944,18 @@ inline unsigned count_digits(uint64_t n) {
// Optional version of count_digits for better performance on 32-bit platforms.
inline unsigned count_digits(uint32_t n) {
int t = (32 - FMT_BUILTIN_CLZ(n | 1)) * 1233 >> 12;
return to_unsigned(t) - (n < Data::POWERS_OF_10_32[t]) + 1;
return to_unsigned(t) - (n < data::POWERS_OF_10_32[t]) + 1;
}
#endif
// A functor that doesn't add a thousands separator.
struct NoThousandsSep {
struct no_thousands_sep {
template <typename Char>
void operator()(Char *) {}
};
// A functor that adds a thousands separator.
class ThousandsSep {
class add_thousands_sep {
private:
fmt::string_view sep_;
@ -963,7 +963,8 @@ class ThousandsSep {
unsigned digit_index_;
public:
explicit ThousandsSep(fmt::string_view sep) : sep_(sep), digit_index_(0) {}
explicit add_thousands_sep(fmt::string_view sep)
: sep_(sep), digit_index_(0) {}
template <typename Char>
void operator()(Char *&buffer) {
@ -988,9 +989,9 @@ inline void format_decimal(Char *buffer, UInt value, unsigned num_digits,
// "Three Optimization Tips for C++". See speed-test for a comparison.
unsigned index = static_cast<unsigned>((value % 100) * 2);
value /= 100;
*--buffer = Data::DIGITS[index + 1];
*--buffer = data::DIGITS[index + 1];
thousands_sep(buffer);
*--buffer = Data::DIGITS[index];
*--buffer = data::DIGITS[index];
thousands_sep(buffer);
}
if (value < 10) {
@ -998,14 +999,14 @@ inline void format_decimal(Char *buffer, UInt value, unsigned num_digits,
return;
}
unsigned index = static_cast<unsigned>(value * 2);
*--buffer = Data::DIGITS[index + 1];
*--buffer = data::DIGITS[index + 1];
thousands_sep(buffer);
*--buffer = Data::DIGITS[index];
*--buffer = data::DIGITS[index];
}
template <typename UInt, typename Char>
inline void format_decimal(Char *buffer, UInt value, unsigned num_digits) {
return format_decimal(buffer, value, num_digits, NoThousandsSep());
return format_decimal(buffer, value, num_digits, no_thousands_sep());
}
#ifndef _WIN32
@ -1019,12 +1020,12 @@ inline void format_decimal(Char *buffer, UInt value, unsigned num_digits) {
#if FMT_USE_WINDOWS_H
// A converter from UTF-8 to UTF-16.
// It is only provided for Windows since other systems support UTF-8 natively.
class UTF8ToUTF16 {
class utf8_to_utf16 {
private:
MemoryBuffer<wchar_t, INLINE_BUFFER_SIZE> buffer_;
wmemory_buffer buffer_;
public:
FMT_API explicit UTF8ToUTF16(string_view s);
FMT_API explicit utf8_to_utf16(string_view s);
operator wstring_view() const { return wstring_view(&buffer_[0], size()); }
size_t size() const { return buffer_.size() - 1; }
const wchar_t *c_str() const { return &buffer_[0]; }
@ -1035,7 +1036,7 @@ class UTF8ToUTF16 {
// It is only provided for Windows since other systems support UTF-8 natively.
class UTF16ToUTF8 {
private:
MemoryBuffer<char, INLINE_BUFFER_SIZE> buffer_;
memory_buffer buffer_;
public:
UTF16ToUTF8() {}
@ -1055,21 +1056,6 @@ FMT_API void format_windows_error(fmt::buffer &out, int error_code,
fmt::string_view message) FMT_NOEXCEPT;
#endif
template<bool B, class T = void>
struct EnableIf {};
template<class T>
struct EnableIf<true, T> { typedef T type; };
template<bool B, class T, class F>
struct Conditional { typedef T type; };
template<class T, class F>
struct Conditional<false, T, F> { typedef F type; };
template <typename T>
struct False { enum { value = 0 }; };
template <typename T = void>
struct Null {};
@ -1146,7 +1132,7 @@ struct string_value {
};
template <typename Char>
struct CustomValue {
struct custom_value {
typedef void (*FormatFunc)(
basic_buffer<Char> &buffer, const void *arg, void *ctx);
@ -1229,7 +1215,7 @@ class value {
string_value<signed char> sstring;
string_value<unsigned char> ustring;
string_value<typename Context::char_type> tstring;
CustomValue<typename Context::char_type> custom;
custom_value<typename Context::char_type> custom;
};
typedef typename Context::char_type Char;
@ -1358,7 +1344,7 @@ class value {
template <typename T>
value(const T &value,
typename EnableIf<!ConvertToInt<T>::value, int>::type = 0) {
typename enable_if<!ConvertToInt<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>;
@ -1366,7 +1352,7 @@ class value {
template <typename T>
value(const T &value,
typename EnableIf<ConvertToInt<T>::value, int>::type = 0) {
typename enable_if<ConvertToInt<T>::value, int>::type = 0) {
static_assert(internal::type<T>() == internal::INT, "invalid type");
this->int_value = value;
}
@ -1528,10 +1514,10 @@ inline fmt::string_view thousands_sep(...) { return ""; }
template <typename Formatter, typename T, typename Char>
void format_value(basic_buffer<Char> &, const T &, Formatter &, const Char *) {
FMT_STATIC_ASSERT(False<T>::value,
FMT_STATIC_ASSERT(sizeof(T) < 0,
"Cannot format argument. To enable the use of ostream "
"operator<< include fmt/ostream.h. Otherwise provide "
"an overload of format_arg.");
"an overload of format_value.");
}
template <typename Context>
@ -1933,18 +1919,18 @@ class ArgFormatterBase {
}
template <typename StrChar>
void write_str(basic_string_view<StrChar> value,
typename EnableIf<
std::is_same<Char, wchar_t>::value &&
std::is_same<StrChar, wchar_t>::value, int>::type = 0) {
typename enable_if<
std::is_same<Char, wchar_t>::value &&
std::is_same<StrChar, wchar_t>::value>::type
write_str(basic_string_view<StrChar> value) {
writer_.write_str(value, spec_);
}
template <typename StrChar>
void write_str(basic_string_view<StrChar> value,
typename EnableIf<
!std::is_same<Char, wchar_t>::value ||
!std::is_same<StrChar, wchar_t>::value, int>::type = 0) {
typename enable_if<
!std::is_same<Char, wchar_t>::value ||
!std::is_same<StrChar, wchar_t>::value>::type
write_str(basic_string_view<StrChar> value) {
// Do nothing.
}
@ -1994,7 +1980,7 @@ class ArgFormatterBase {
if (spec_.align_ == ALIGN_NUMERIC || spec_.flags_ != 0)
FMT_THROW(format_error("invalid format specifier for char"));
typedef typename basic_writer<Char>::CharPtr CharPtr;
Char fill = internal::CharTraits<Char>::cast(spec_.fill());
Char fill = internal::char_traits<Char>::cast(spec_.fill());
CharPtr out = CharPtr();
const unsigned CHAR_WIDTH = 1;
if (spec_.width_ > CHAR_WIDTH) {
@ -2012,7 +1998,7 @@ class ArgFormatterBase {
} else {
out = writer_.grow_buffer(CHAR_WIDTH);
}
*out = internal::CharTraits<Char>::cast(value);
*out = internal::char_traits<Char>::cast(value);
}
void operator()(const char *value) {
@ -2116,7 +2102,7 @@ class arg_formatter : public internal::ArgFormatterBase<Char> {
using internal::ArgFormatterBase<Char>::operator();
/** Formats an argument of a custom (user-defined) type. */
void operator()(internal::CustomValue<Char> c) {
void operator()(internal::custom_value<Char> c) {
c.format(this->writer().buffer(), c.value, &ctx_);
}
};
@ -2260,7 +2246,7 @@ class basic_writer {
FMT_DISALLOW_COPY_AND_ASSIGN(basic_writer);
typedef typename internal::CharTraits<Char>::CharPtr CharPtr;
typedef typename internal::char_traits<Char>::CharPtr CharPtr;
#if FMT_SECURE_SCL
// Returns pointer value.
@ -2294,8 +2280,8 @@ class basic_writer {
// Writes a decimal integer.
template <typename Int>
void write_decimal(Int value) {
typedef typename internal::IntTraits<Int>::MainType MainType;
MainType abs_value = static_cast<MainType>(value);
typedef typename internal::int_traits<Int>::main_type main_type;
main_type abs_value = static_cast<main_type>(value);
if (internal::is_negative(value)) {
abs_value = 0 - abs_value;
*write_unsigned_decimal(abs_value, 1) = '-';
@ -2478,7 +2464,7 @@ typename basic_writer<Char>::CharPtr basic_writer<Char>::write_str(
CharPtr out = CharPtr();
if (spec.width() > size) {
out = grow_buffer(spec.width());
Char fill = internal::CharTraits<Char>::cast(spec.fill());
Char fill = internal::char_traits<Char>::cast(spec.fill());
if (spec.align() == ALIGN_RIGHT) {
std::uninitialized_fill_n(out, spec.width() - size, fill);
out += spec.width() - size;
@ -2499,7 +2485,7 @@ template <typename StrChar>
void basic_writer<Char>::write_str(
basic_string_view<StrChar> s, const format_specs &spec) {
// Check if StrChar is convertible to Char.
internal::CharTraits<Char>::convert(StrChar());
internal::char_traits<Char>::convert(StrChar());
if (spec.type_ && spec.type_ != 's')
internal::report_unknown_type(spec.type_, "string");
const StrChar *str_value = s.data();
@ -2521,7 +2507,7 @@ typename basic_writer<Char>::CharPtr basic_writer<Char>::fill_padding(
std::size_t content_size, wchar_t fill) {
std::size_t padding = total_size - content_size;
std::size_t left_padding = padding / 2;
Char fill_char = internal::CharTraits<Char>::cast(fill);
Char fill_char = internal::char_traits<Char>::cast(fill);
std::uninitialized_fill_n(buffer, left_padding, fill_char);
buffer += left_padding;
CharPtr content = buffer;
@ -2537,7 +2523,7 @@ typename basic_writer<Char>::CharPtr basic_writer<Char>::prepare_int_buffer(
const char *prefix, unsigned prefix_size) {
unsigned width = spec.width();
Alignment align = spec.align();
Char fill = internal::CharTraits<Char>::cast(spec.fill());
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
// is specified.
@ -2597,7 +2583,7 @@ template <typename Char>
template <typename T, typename Spec>
void basic_writer<Char>::write_int(T value, Spec spec) {
unsigned prefix_size = 0;
typedef typename internal::IntTraits<T>::MainType UnsignedType;
typedef typename internal::int_traits<T>::main_type UnsignedType;
UnsignedType abs_value = static_cast<UnsignedType>(value);
char prefix[4] = "";
if (internal::is_negative(value)) {
@ -2673,7 +2659,8 @@ void basic_writer<Char>::write_int(T value, Spec spec) {
unsigned size = static_cast<unsigned>(
num_digits + sep.size() * ((num_digits - 1) / 3));
CharPtr p = prepare_int_buffer(size, spec, prefix, prefix_size) + 1;
internal::format_decimal(get(p), abs_value, 0, internal::ThousandsSep(sep));
internal::format_decimal(get(p), abs_value, 0,
internal::add_thousands_sep(sep));
break;
}
default:
@ -2784,7 +2771,7 @@ void basic_writer<Char>::write_double(T value, const format_specs &spec) {
*format_ptr = '\0';
// Format using snprintf.
Char fill = internal::CharTraits<Char>::cast(spec.fill());
Char fill = internal::char_traits<Char>::cast(spec.fill());
unsigned n = 0;
Char *start = 0;
for (;;) {
@ -2799,7 +2786,7 @@ void basic_writer<Char>::write_double(T value, const format_specs &spec) {
}
#endif
start = &buffer_[offset];
int result = internal::CharTraits<Char>::format_float(
int result = internal::char_traits<Char>::format_float(
start, buffer_size, format, width_for_sprintf, spec.precision(), value);
if (result >= 0) {
n = internal::to_unsigned(result);
@ -3015,16 +3002,16 @@ class FormatInt {
// "Three Optimization Tips for C++". See speed-test for a comparison.
unsigned index = static_cast<unsigned>((value % 100) * 2);
value /= 100;
*--buffer_end = internal::Data::DIGITS[index + 1];
*--buffer_end = internal::Data::DIGITS[index];
*--buffer_end = internal::data::DIGITS[index + 1];
*--buffer_end = internal::data::DIGITS[index];
}
if (value < 10) {
*--buffer_end = static_cast<char>('0' + value);
return buffer_end;
}
unsigned index = static_cast<unsigned>(value * 2);
*--buffer_end = internal::Data::DIGITS[index + 1];
*--buffer_end = internal::Data::DIGITS[index];
*--buffer_end = internal::data::DIGITS[index + 1];
*--buffer_end = internal::data::DIGITS[index];
return buffer_end;
}
@ -3079,8 +3066,8 @@ class FormatInt {
// write a terminating null character.
template <typename T>
inline void format_decimal(char *&buffer, T value) {
typedef typename internal::IntTraits<T>::MainType MainType;
MainType abs_value = static_cast<MainType>(value);
typedef typename internal::int_traits<T>::main_type main_type;
main_type abs_value = static_cast<main_type>(value);
if (internal::is_negative(value)) {
*buffer++ = '-';
abs_value = 0 - abs_value;
@ -3091,8 +3078,8 @@ inline void format_decimal(char *&buffer, T value) {
return;
}
unsigned index = static_cast<unsigned>(abs_value * 2);
*buffer++ = internal::Data::DIGITS[index];
*buffer++ = internal::Data::DIGITS[index + 1];
*buffer++ = internal::data::DIGITS[index];
*buffer++ = internal::data::DIGITS[index + 1];
return;
}
unsigned num_digits = internal::count_digits(abs_value);
@ -3211,7 +3198,7 @@ class CustomFormatter {
CustomFormatter(basic_buffer<Char> &buffer, Context &ctx)
: buffer_(buffer), ctx_(ctx) {}
bool operator()(internal::CustomValue<Char> custom) {
bool operator()(internal::custom_value<Char> custom) {
custom.format(buffer_, custom.value, &ctx_);
return true;
}

View File

@ -14,7 +14,7 @@ namespace fmt {
namespace internal {
FMT_FUNC void write(std::ostream &os, buffer &buf) {
const char *data = buf.data();
typedef internal::MakeUnsigned<std::streamsize>::Type UnsignedStreamSize;
typedef internal::make_unsigned<std::streamsize>::type UnsignedStreamSize;
UnsignedStreamSize size = buf.size();
UnsignedStreamSize max_size =
internal::to_unsigned((std::numeric_limits<std::streamsize>::max)());

View File

@ -101,7 +101,7 @@ class ArgConverter {
typename std::enable_if<std::is_integral<U>::value>::type
operator()(U value) {
bool is_signed = type_ == 'd' || type_ == 'i';
typedef typename internal::Conditional<
typedef typename internal::conditional<
is_same<T, void>::value, U, T>::type TargetType;
typedef basic_context<Char> context;
if (sizeof(TargetType) <= sizeof(int)) {
@ -110,7 +110,7 @@ class ArgConverter {
arg_ = internal::make_arg<Context>(
static_cast<int>(static_cast<TargetType>(value)));
} else {
typedef typename internal::MakeUnsigned<TargetType>::Type Unsigned;
typedef typename internal::make_unsigned<TargetType>::type Unsigned;
arg_ = internal::make_arg<Context>(
static_cast<unsigned>(static_cast<Unsigned>(value)));
}
@ -122,7 +122,7 @@ class ArgConverter {
arg_ = internal::make_arg<Context>(static_cast<long_long>(value));
} else {
arg_ = internal::make_arg<Context>(
static_cast<typename internal::MakeUnsigned<U>::Type>(value));
static_cast<typename internal::make_unsigned<U>::type>(value));
}
}
}
@ -183,7 +183,7 @@ class PrintfWidthHandler {
template <typename T>
typename std::enable_if<std::is_integral<T>::value, unsigned>::type
operator()(T value) {
typedef typename internal::IntTraits<T>::MainType UnsignedType;
typedef typename internal::int_traits<T>::main_type UnsignedType;
UnsignedType width = static_cast<UnsignedType>(value);
if (internal::is_negative(value)) {
spec_.align_ = ALIGN_LEFT;
@ -285,7 +285,7 @@ class printf_arg_formatter : public internal::ArgFormatterBase<Char> {
}
/** Formats an argument of a custom (user-defined) type. */
void operator()(internal::CustomValue<Char> c) {
void operator()(internal::custom_value<Char> c) {
const Char format_str[] = {'}', '\0'};
auto args = basic_args<basic_context<Char>>();
basic_context<Char> ctx(format_str, args);

View File

@ -1531,7 +1531,7 @@ class MockArgFormatter : public fmt::internal::ArgFormatterBase<char> {
void operator()(int value) { call(value); }
void operator()(fmt::internal::CustomValue<char>) {}
void operator()(fmt::internal::custom_value<char>) {}
};
void custom_vformat(fmt::CStringRef format_str, fmt::args args) {

View File

@ -155,7 +155,7 @@ TEST(OStreamTest, WriteToOStreamMaxSize) {
const char *data = 0;
std::size_t size = max_size;
do {
typedef fmt::internal::MakeUnsigned<std::streamsize>::Type UStreamSize;
typedef fmt::internal::make_unsigned<std::streamsize>::type UStreamSize;
UStreamSize n = std::min<UStreamSize>(
size, fmt::internal::to_unsigned(max_streamsize));
EXPECT_CALL(streambuf, xsputn(data, static_cast<std::streamsize>(n)))

View File

@ -279,7 +279,7 @@ TEST(FileTest, Size) {
EXPECT_GE(f.size(), 0);
EXPECT_EQ(content.size(), static_cast<fmt::ulong_long>(f.size()));
#ifdef _WIN32
fmt::internal::MemoryBuffer<char> message;
fmt::memory_buffer message;
fmt::internal::format_windows_error(
message, ERROR_ACCESS_DENIED, "cannot get file size");
fstat_sim = ERROR;

View File

@ -277,11 +277,11 @@ TEST(PrintfTest, DynamicPrecision) {
}
template <typename T>
struct MakeSigned { typedef T Type; };
struct make_signed { typedef T type; };
#define SPECIALIZE_MAKE_SIGNED(T, S) \
template <> \
struct MakeSigned<T> { typedef S Type; }
struct make_signed<T> { typedef S type; }
SPECIALIZE_MAKE_SIGNED(char, signed char);
SPECIALIZE_MAKE_SIGNED(unsigned char, signed char);
@ -306,13 +306,13 @@ void TestLength(const char *length_spec, U value) {
signed_value = static_cast<unsigned>(value);
unsigned_value = static_cast<unsigned>(value);
}
using fmt::internal::MakeUnsigned;
using fmt::internal::make_unsigned;
if (sizeof(U) <= sizeof(int) && sizeof(int) < sizeof(T)) {
signed_value = static_cast<fmt::long_long>(value);
unsigned_value = static_cast<typename MakeUnsigned<unsigned>::Type>(value);
unsigned_value = static_cast<typename make_unsigned<unsigned>::type>(value);
} else {
signed_value = static_cast<typename MakeSigned<T>::Type>(value);
unsigned_value = static_cast<typename MakeUnsigned<T>::Type>(value);
signed_value = static_cast<typename make_signed<T>::type>(value);
unsigned_value = static_cast<typename make_unsigned<T>::type>(value);
}
std::ostringstream os;
os << signed_value;

View File

@ -383,7 +383,7 @@ TEST(MemoryBufferTest, ExceptionInDeallocate) {
TEST(FixedBufferTest, Ctor) {
char array[10] = "garbage";
fmt::FixedBuffer<char> buffer(array, sizeof(array));
fmt::basic_fixed_buffer<char> buffer(array, sizeof(array));
EXPECT_EQ(0u, buffer.size());
EXPECT_EQ(10u, buffer.capacity());
EXPECT_EQ(array, buffer.data());
@ -391,7 +391,7 @@ TEST(FixedBufferTest, Ctor) {
TEST(FixedBufferTest, CompileTimeSizeCtor) {
char array[10] = "garbage";
fmt::FixedBuffer<char> buffer(array);
fmt::basic_fixed_buffer<char> buffer(array);
EXPECT_EQ(0u, buffer.size());
EXPECT_EQ(10u, buffer.capacity());
EXPECT_EQ(array, buffer.data());
@ -399,7 +399,7 @@ TEST(FixedBufferTest, CompileTimeSizeCtor) {
TEST(FixedBufferTest, BufferOverflow) {
char array[10];
fmt::FixedBuffer<char> buffer(array);
fmt::basic_fixed_buffer<char> buffer(array);
buffer.resize(10);
EXPECT_THROW_MSG(buffer.resize(11), std::runtime_error, "buffer overflow");
}
@ -445,7 +445,7 @@ namespace fmt {
namespace internal {
template <typename Char>
bool operator==(CustomValue<Char> lhs, CustomValue<Char> rhs) {
bool operator==(custom_value<Char> lhs, custom_value<Char> rhs) {
return lhs.value == rhs.value;
}
}
@ -575,10 +575,10 @@ TEST(UtilTest, PointerArg) {
TEST(UtilTest, CustomArg) {
::Test test;
typedef MockVisitor<fmt::internal::CustomValue<char>> Visitor;
typedef MockVisitor<fmt::internal::custom_value<char>> Visitor;
testing::StrictMock<Visitor> visitor;
EXPECT_CALL(visitor, visit(_)).WillOnce(
testing::Invoke([&](fmt::internal::CustomValue<char> custom) {
testing::Invoke([&](fmt::internal::custom_value<char> custom) {
EXPECT_EQ(&test, custom.value);
fmt::memory_buffer buffer;
fmt::context ctx("}", fmt::args());
@ -659,7 +659,7 @@ TEST(UtilTest, UTF16ToUTF8) {
TEST(UtilTest, UTF8ToUTF16) {
std::string s = "лошадка";
fmt::internal::UTF8ToUTF16 u(s.c_str());
fmt::internal::utf8_to_utf16 u(s.c_str());
EXPECT_EQ(L"\x043B\x043E\x0448\x0430\x0434\x043A\x0430", u.str());
EXPECT_EQ(7, u.size());
}
@ -668,7 +668,7 @@ template <typename Converter, typename Char>
void check_utf_conversion_error(
const char *message,
fmt::basic_string_view<Char> str = fmt::basic_string_view<Char>(0, 0)) {
fmt::internal::MemoryBuffer<char> out;
fmt::memory_buffer out;
fmt::internal::format_windows_error(out, ERROR_INVALID_PARAMETER, message);
fmt::SystemError error(0, "");
try {
@ -687,8 +687,8 @@ TEST(UtilTest, UTF16ToUTF8Error) {
TEST(UtilTest, UTF8ToUTF16Error) {
const char *message = "cannot convert string from UTF-8 to UTF-16";
check_utf_conversion_error<fmt::internal::UTF8ToUTF16, char>(message);
check_utf_conversion_error<fmt::internal::UTF8ToUTF16, char>(
check_utf_conversion_error<fmt::internal::utf8_to_utf16, char>(message);
check_utf_conversion_error<fmt::internal::utf8_to_utf16, char>(
message, fmt::string_view("foo", INT_MAX + 1u));
}
@ -753,7 +753,7 @@ TEST(UtilTest, FormatWindowsError) {
reinterpret_cast<LPWSTR>(&message), 0, 0);
fmt::internal::UTF16ToUTF8 utf8_message(message);
LocalFree(message);
fmt::internal::MemoryBuffer<char> actual_message;
fmt::memory_buffer actual_message;
fmt::internal::format_windows_error(
actual_message, ERROR_FILE_EXISTS, "test");
EXPECT_EQ(fmt::format("test: {}", utf8_message.str()),
@ -780,7 +780,7 @@ TEST(UtilTest, FormatLongWindowsError) {
}
fmt::internal::UTF16ToUTF8 utf8_message(message);
LocalFree(message);
fmt::internal::MemoryBuffer<char> actual_message;
fmt::memory_buffer actual_message;
fmt::internal::format_windows_error(
actual_message, provisioning_not_allowed, "test");
EXPECT_EQ(fmt::format("test: {}", utf8_message.str()),
@ -793,7 +793,7 @@ TEST(UtilTest, WindowsError) {
}
TEST(UtilTest, ReportWindowsError) {
fmt::internal::MemoryBuffer<char> out;
fmt::memory_buffer out;
fmt::internal::format_windows_error(out, ERROR_FILE_EXISTS, "test error");
out.push_back('\n');
EXPECT_WRITE(stderr,
@ -820,13 +820,13 @@ TEST(UtilTest, IsEnumConvertibleToInt) {
template <typename T>
bool check_enable_if(
typename fmt::internal::EnableIf<sizeof(T) == sizeof(int), T>::type *) {
typename fmt::internal::enable_if<sizeof(T) == sizeof(int), T>::type *) {
return true;
}
template <typename T>
bool check_enable_if(
typename fmt::internal::EnableIf<sizeof(T) != sizeof(int), T>::type *) {
typename fmt::internal::enable_if<sizeof(T) != sizeof(int), T>::type *) {
return false;
}
@ -839,10 +839,10 @@ TEST(UtilTest, EnableIf) {
TEST(UtilTest, Conditional) {
int i = 0;
fmt::internal::Conditional<true, int, char>::type *pi = &i;
fmt::internal::conditional<true, int, char>::type *pi = &i;
(void)pi;
char c = 0;
fmt::internal::Conditional<false, int, char>::type *pc = &c;
fmt::internal::conditional<false, int, char>::type *pc = &c;
(void)pc;
}