From d8fd1699b17e47a527b83733cd80218a40fbc88e Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 3 Jul 2019 16:14:14 -0700 Subject: [PATCH] Make data names follow naming conventions --- include/fmt/color.h | 14 +++++------ include/fmt/format-inl.h | 32 ++++++++++++------------ include/fmt/format.h | 54 ++++++++++++++++++++-------------------- 3 files changed, 50 insertions(+), 50 deletions(-) diff --git a/include/fmt/color.h b/include/fmt/color.h index ddf27e7c..031e4d67 100644 --- a/include/fmt/color.h +++ b/include/fmt/color.h @@ -358,7 +358,7 @@ template struct ansi_color_escape { // If we have a terminal color, we need to output another escape code // sequence. if (!text_color.is_rgb) { - bool is_background = esc == internal::data::BACKGROUND_COLOR; + bool is_background = esc == internal::data::background_color; uint32_t value = text_color.value.term_color; // Background ASCII codes are the same as the foreground ones but with // 10 more. @@ -430,13 +430,13 @@ template struct ansi_color_escape { template FMT_CONSTEXPR ansi_color_escape make_foreground_color( internal::color_type foreground) FMT_NOEXCEPT { - return ansi_color_escape(foreground, internal::data::FOREGROUND_COLOR); + return ansi_color_escape(foreground, internal::data::foreground_color); } template FMT_CONSTEXPR ansi_color_escape make_background_color( internal::color_type background) FMT_NOEXCEPT { - return ansi_color_escape(background, internal::data::BACKGROUND_COLOR); + return ansi_color_escape(background, internal::data::background_color); } template @@ -455,17 +455,17 @@ inline void fputs(const wchar_t* chars, FILE* stream) FMT_NOEXCEPT { } template inline void reset_color(FILE* stream) FMT_NOEXCEPT { - fputs(internal::data::RESET_COLOR, stream); + fputs(internal::data::reset_color, stream); } template <> inline void reset_color(FILE* stream) FMT_NOEXCEPT { - fputs(internal::data::WRESET_COLOR, stream); + fputs(internal::data::wreset_color, stream); } template inline void reset_color(basic_memory_buffer& buffer) FMT_NOEXCEPT { - const char* begin = data::RESET_COLOR; - const char* end = begin + sizeof(data::RESET_COLOR) - 1; + const char* begin = data::reset_color; + const char* end = begin + sizeof(data::reset_color) - 1; buffer.append(begin, end); } diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 2343575b..6d537f11 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -255,7 +255,7 @@ int format_float(char* buf, std::size_t size, const char* format, int precision, } template -const char basic_data::DIGITS[] = +const char basic_data::digits[] = "0001020304050607080910111213141516171819" "2021222324252627282930313233343536373839" "4041424344454647484950515253545556575859" @@ -263,7 +263,7 @@ const char basic_data::DIGITS[] = "8081828384858687888990919293949596979899"; template -const char basic_data::HEX_DIGITS[] = "0123456789abcdef"; +const char basic_data::hex_digits[] = "0123456789abcdef"; #define FMT_POWERS_OF_10(factor) \ factor * 10, factor * 100, factor * 1000, factor * 10000, factor * 100000, \ @@ -271,23 +271,23 @@ const char basic_data::HEX_DIGITS[] = "0123456789abcdef"; factor * 1000000000 template -const uint64_t basic_data::POWERS_OF_10_64[] = { +const uint64_t basic_data::powers_of_10_64[] = { 1, FMT_POWERS_OF_10(1), FMT_POWERS_OF_10(1000000000ull), 10000000000000000000ull}; template -const uint32_t basic_data::ZERO_OR_POWERS_OF_10_32[] = {0, +const uint32_t basic_data::zero_or_powers_of_10_32[] = {0, FMT_POWERS_OF_10(1)}; template -const uint64_t basic_data::ZERO_OR_POWERS_OF_10_64[] = { +const uint64_t basic_data::zero_or_powers_of_10_64[] = { 0, FMT_POWERS_OF_10(1), FMT_POWERS_OF_10(1000000000ull), 10000000000000000000ull}; // Normalized 64-bit significands of pow(10, k), for k = -348, -340, ..., 340. // These are generated by support/compute-powers.py. template -const uint64_t basic_data::POW10_SIGNIFICANDS[] = { +const uint64_t basic_data::pow10_significands[] = { 0xfa8fd5a0081c0288, 0xbaaee17fa23ebf76, 0x8b16fb203055ac76, 0xcf42894a5dce35ea, 0x9a6bb0aa55653b2d, 0xe61acf033d1a45df, 0xab70fe17c79ac6ca, 0xff77b1fcbebcdc4f, 0xbe5691ef416bd60c, @@ -322,7 +322,7 @@ const uint64_t basic_data::POW10_SIGNIFICANDS[] = { // Binary exponents of pow(10, k), for k = -348, -340, ..., 340, corresponding // to significands above. template -const int16_t basic_data::POW10_EXPONENTS[] = { +const int16_t basic_data::pow10_exponents[] = { -1220, -1193, -1166, -1140, -1113, -1087, -1060, -1034, -1007, -980, -954, -927, -901, -874, -847, -821, -794, -768, -741, -715, -688, -661, -635, -608, -582, -555, -529, -502, -475, -449, -422, -396, -369, @@ -333,11 +333,11 @@ const int16_t basic_data::POW10_EXPONENTS[] = { 827, 853, 880, 907, 933, 960, 986, 1013, 1039, 1066}; template -const char basic_data::FOREGROUND_COLOR[] = "\x1b[38;2;"; +const char basic_data::foreground_color[] = "\x1b[38;2;"; template -const char basic_data::BACKGROUND_COLOR[] = "\x1b[48;2;"; -template const char basic_data::RESET_COLOR[] = "\x1b[0m"; -template const wchar_t basic_data::WRESET_COLOR[] = L"\x1b[0m"; +const char basic_data::background_color[] = "\x1b[48;2;"; +template const char basic_data::reset_color[] = "\x1b[0m"; +template const wchar_t basic_data::wreset_color[] = L"\x1b[0m"; template struct bits { static FMT_CONSTEXPR_DECL const int value = @@ -455,7 +455,7 @@ FMT_FUNC fp get_cached_power(int min_exponent, int& pow10_exponent) { const int dec_exp_step = 8; index = (index - first_dec_exp - 1) / dec_exp_step + 1; pow10_exponent = first_dec_exp + index * dec_exp_step; - return fp(data::POW10_SIGNIFICANDS[index], data::POW10_EXPONENTS[index]); + return fp(data::pow10_significands[index], data::pow10_exponents[index]); } enum round_direction { unknown, up, down }; @@ -505,7 +505,7 @@ digits::result grisu_gen_digits(fp value, uint64_t error, int& exp, uint64_t fractional = value.f & (one.f - 1); exp = count_digits(integral); // kappa in Grisu. // Divide by 10 to prevent overflow. - auto result = handler.on_start(data::POWERS_OF_10_64[exp - 1] << -one.e, + auto result = handler.on_start(data::powers_of_10_64[exp - 1] << -one.e, value.f / 10, error * 10, exp); if (result != digits::more) return result; // Generate digits for the integral part. This can produce up to 10 digits. @@ -561,7 +561,7 @@ digits::result grisu_gen_digits(fp value, uint64_t error, int& exp, uint64_t remainder = (static_cast(integral) << -one.e) + fractional; result = handler.on_digit(static_cast('0' + digit), - data::POWERS_OF_10_64[exp] << -one.e, remainder, + data::powers_of_10_64[exp] << -one.e, remainder, error, exp, true); if (result != digits::more) return result; } while (exp > 0); @@ -658,11 +658,11 @@ template struct grisu_shortest_handler { buf[size++] = digit; if (remainder >= error) return digits::more; if (GRISU_VERSION != 3) { - uint64_t d = integral ? diff : diff * data::POWERS_OF_10_64[-exp]; + uint64_t d = integral ? diff : diff * data::powers_of_10_64[-exp]; round(d, divisor, remainder, error); return digits::done; } - uint64_t unit = integral ? 1 : data::POWERS_OF_10_64[-exp]; + uint64_t unit = integral ? 1 : data::powers_of_10_64[-exp]; uint64_t up = (diff - 1) * unit; // wp_Wup round(up, divisor, remainder, error); uint64_t down = (diff + 1) * unit; // wp_Wdown diff --git a/include/fmt/format.h b/include/fmt/format.h index 62418fb3..8b08bb20 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -614,17 +614,17 @@ using uint32_or_64_t = // Static data is placed in this class template for the header-only config. template struct FMT_EXTERN_TEMPLATE_API basic_data { - static const uint64_t POWERS_OF_10_64[]; - static const uint32_t ZERO_OR_POWERS_OF_10_32[]; - static const uint64_t ZERO_OR_POWERS_OF_10_64[]; - static const uint64_t POW10_SIGNIFICANDS[]; - static const int16_t POW10_EXPONENTS[]; - static const char DIGITS[]; - static const char HEX_DIGITS[]; - static const char FOREGROUND_COLOR[]; - static const char BACKGROUND_COLOR[]; - static const char RESET_COLOR[5]; - static const wchar_t WRESET_COLOR[5]; + static const uint64_t powers_of_10_64[]; + static const uint32_t zero_or_powers_of_10_32[]; + static const uint64_t zero_or_powers_of_10_64[]; + static const uint64_t pow10_significands[]; + static const int16_t pow10_exponents[]; + static const char digits[]; + static const char hex_digits[]; + static const char foreground_color[]; + static const char background_color[]; + static const char reset_color[5]; + static const wchar_t wreset_color[5]; }; FMT_EXTERN template struct basic_data; @@ -639,7 +639,7 @@ inline int 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 t - (n < data::ZERO_OR_POWERS_OF_10_64[t]) + 1; + return t - (n < data::zero_or_powers_of_10_64[t]) + 1; } #else // Fallback version of count_digits used when __builtin_clz is not available. @@ -700,7 +700,7 @@ class decimal_formatter { char* buffer_; void write_pair(unsigned N, uint32_t index) { - std::memcpy(buffer_ + N, data::DIGITS + index * 2, 2); + std::memcpy(buffer_ + N, data::digits + index * 2, 2); } public: @@ -717,7 +717,7 @@ class decimal_formatter { unsigned n = N - 1; unsigned a = n / 5 * n * 53 / 16; uint64_t t = - ((1ULL << (32 + a)) / data::ZERO_OR_POWERS_OF_10_32[n] + 1 - n / 9); + ((1ULL << (32 + a)) / data::zero_or_powers_of_10_32[n] + 1 - n / 9); t = ((t * u) >> a) + n / 5 * 4; write_pair(0, t >> 32); for (unsigned i = 2; i < N; i += 2) { @@ -737,7 +737,7 @@ class decimal_formatter { // Optional version of count_digits for better performance on 32-bit platforms. inline int count_digits(uint32_t n) { int t = (32 - FMT_BUILTIN_CLZ(n | 1)) * 1233 >> 12; - return t - (n < data::ZERO_OR_POWERS_OF_10_32[t]) + 1; + return t - (n < data::zero_or_powers_of_10_32[t]) + 1; } #endif @@ -766,9 +766,9 @@ inline Char* format_decimal(Char* buffer, UInt value, int num_digits, // "Three Optimization Tips for C++". See speed-test for a comparison. unsigned index = static_cast((value % 100) * 2); value /= 100; - *--buffer = static_cast(data::DIGITS[index + 1]); + *--buffer = static_cast(data::digits[index + 1]); thousands_sep(buffer); - *--buffer = static_cast(data::DIGITS[index]); + *--buffer = static_cast(data::digits[index]); thousands_sep(buffer); } if (value < 10) { @@ -776,9 +776,9 @@ inline Char* format_decimal(Char* buffer, UInt value, int num_digits, return end; } unsigned index = static_cast(value * 2); - *--buffer = static_cast(data::DIGITS[index + 1]); + *--buffer = static_cast(data::digits[index + 1]); thousands_sep(buffer); - *--buffer = static_cast(data::DIGITS[index]); + *--buffer = static_cast(data::digits[index]); return end; } @@ -805,7 +805,7 @@ inline Char* format_uint(Char* buffer, UInt value, int num_digits, buffer += num_digits; Char* end = buffer; do { - const char* digits = upper ? "0123456789ABCDEF" : data::HEX_DIGITS; + const char* digits = upper ? "0123456789ABCDEF" : data::hex_digits; unsigned digit = (value & ((1 << BASE_BITS) - 1)); *--buffer = static_cast(BASE_BITS < 4 ? static_cast('0' + digit) : digits[digit]); @@ -828,7 +828,7 @@ Char* format_uint(Char* buffer, internal::fallback_uintptr n, int num_digits, auto p = buffer; for (int i = 0; i < char_digits; ++i) { unsigned digit = (value & ((1 << BASE_BITS) - 1)); - *--p = static_cast(data::HEX_DIGITS[digit]); + *--p = static_cast(data::hex_digits[digit]); value >>= BASE_BITS; } } @@ -972,11 +972,11 @@ template It write_exponent(int exp, It it) { if (exp >= 100) { *it++ = static_cast(static_cast('0' + exp / 100)); exp %= 100; - const char* d = data::DIGITS + exp * 2; + const char* d = data::digits + exp * 2; *it++ = static_cast(d[0]); *it++ = static_cast(d[1]); } else { - const char* d = data::DIGITS + exp * 2; + const char* d = data::digits + exp * 2; *it++ = static_cast(d[0]); *it++ = static_cast(d[1]); } @@ -2813,16 +2813,16 @@ class format_int { // "Three Optimization Tips for C++". See speed-test for a comparison. unsigned index = static_cast((value % 100) * 2); value /= 100; - *--ptr = internal::data::DIGITS[index + 1]; - *--ptr = internal::data::DIGITS[index]; + *--ptr = internal::data::digits[index + 1]; + *--ptr = internal::data::digits[index]; } if (value < 10) { *--ptr = static_cast('0' + value); return ptr; } unsigned index = static_cast(value * 2); - *--ptr = internal::data::DIGITS[index + 1]; - *--ptr = internal::data::DIGITS[index]; + *--ptr = internal::data::digits[index + 1]; + *--ptr = internal::data::digits[index]; return ptr; }