git repos / blockattack-game

blame: source/misc/embedded_libs/fmt-8.1.1/src/format.cc

normal view · raw

f8deb5b9 Poul Sander 2022-01-15 13:55 1
// Formatting library for C++
f8deb5b9 Poul Sander 2022-01-15 13:55 2
//
f8deb5b9 Poul Sander 2022-01-15 13:55 3
// Copyright (c) 2012 - 2016, Victor Zverovich
f8deb5b9 Poul Sander 2022-01-15 13:55 4
// All rights reserved.
f8deb5b9 Poul Sander 2022-01-15 13:55 5
//
f8deb5b9 Poul Sander 2022-01-15 13:55 6
// For the license information refer to format.h.
f8deb5b9 Poul Sander 2022-01-15 13:55 7
f8deb5b9 Poul Sander 2022-01-15 13:55 8
#include "fmt/format-inl.h"
f8deb5b9 Poul Sander 2022-01-15 13:55 9
f8deb5b9 Poul Sander 2022-01-15 13:55 10
FMT_BEGIN_NAMESPACE
f8deb5b9 Poul Sander 2022-01-15 13:55 11
namespace detail {
f8deb5b9 Poul Sander 2022-01-15 13:55 12
f8deb5b9 Poul Sander 2022-01-15 13:55 13
// DEPRECATED!
f8deb5b9 Poul Sander 2022-01-15 13:55 14
template <typename T = void> struct basic_data {
f8deb5b9 Poul Sander 2022-01-15 13:55 15
  FMT_API static constexpr const char digits[100][2] = {
f8deb5b9 Poul Sander 2022-01-15 13:55 16
      {'0', '0'}, {'0', '1'}, {'0', '2'}, {'0', '3'}, {'0', '4'}, {'0', '5'},
f8deb5b9 Poul Sander 2022-01-15 13:55 17
      {'0', '6'}, {'0', '7'}, {'0', '8'}, {'0', '9'}, {'1', '0'}, {'1', '1'},
f8deb5b9 Poul Sander 2022-01-15 13:55 18
      {'1', '2'}, {'1', '3'}, {'1', '4'}, {'1', '5'}, {'1', '6'}, {'1', '7'},
f8deb5b9 Poul Sander 2022-01-15 13:55 19
      {'1', '8'}, {'1', '9'}, {'2', '0'}, {'2', '1'}, {'2', '2'}, {'2', '3'},
f8deb5b9 Poul Sander 2022-01-15 13:55 20
      {'2', '4'}, {'2', '5'}, {'2', '6'}, {'2', '7'}, {'2', '8'}, {'2', '9'},
f8deb5b9 Poul Sander 2022-01-15 13:55 21
      {'3', '0'}, {'3', '1'}, {'3', '2'}, {'3', '3'}, {'3', '4'}, {'3', '5'},
f8deb5b9 Poul Sander 2022-01-15 13:55 22
      {'3', '6'}, {'3', '7'}, {'3', '8'}, {'3', '9'}, {'4', '0'}, {'4', '1'},
f8deb5b9 Poul Sander 2022-01-15 13:55 23
      {'4', '2'}, {'4', '3'}, {'4', '4'}, {'4', '5'}, {'4', '6'}, {'4', '7'},
f8deb5b9 Poul Sander 2022-01-15 13:55 24
      {'4', '8'}, {'4', '9'}, {'5', '0'}, {'5', '1'}, {'5', '2'}, {'5', '3'},
f8deb5b9 Poul Sander 2022-01-15 13:55 25
      {'5', '4'}, {'5', '5'}, {'5', '6'}, {'5', '7'}, {'5', '8'}, {'5', '9'},
f8deb5b9 Poul Sander 2022-01-15 13:55 26
      {'6', '0'}, {'6', '1'}, {'6', '2'}, {'6', '3'}, {'6', '4'}, {'6', '5'},
f8deb5b9 Poul Sander 2022-01-15 13:55 27
      {'6', '6'}, {'6', '7'}, {'6', '8'}, {'6', '9'}, {'7', '0'}, {'7', '1'},
f8deb5b9 Poul Sander 2022-01-15 13:55 28
      {'7', '2'}, {'7', '3'}, {'7', '4'}, {'7', '5'}, {'7', '6'}, {'7', '7'},
f8deb5b9 Poul Sander 2022-01-15 13:55 29
      {'7', '8'}, {'7', '9'}, {'8', '0'}, {'8', '1'}, {'8', '2'}, {'8', '3'},
f8deb5b9 Poul Sander 2022-01-15 13:55 30
      {'8', '4'}, {'8', '5'}, {'8', '6'}, {'8', '7'}, {'8', '8'}, {'8', '9'},
f8deb5b9 Poul Sander 2022-01-15 13:55 31
      {'9', '0'}, {'9', '1'}, {'9', '2'}, {'9', '3'}, {'9', '4'}, {'9', '5'},
f8deb5b9 Poul Sander 2022-01-15 13:55 32
      {'9', '6'}, {'9', '7'}, {'9', '8'}, {'9', '9'}};
f8deb5b9 Poul Sander 2022-01-15 13:55 33
  FMT_API static constexpr const char hex_digits[] = "0123456789abcdef";
f8deb5b9 Poul Sander 2022-01-15 13:55 34
  FMT_API static constexpr const char signs[4] = {0, '-', '+', ' '};
f8deb5b9 Poul Sander 2022-01-15 13:55 35
  FMT_API static constexpr const char left_padding_shifts[5] = {31, 31, 0, 1,
f8deb5b9 Poul Sander 2022-01-15 13:55 36
                                                                0};
f8deb5b9 Poul Sander 2022-01-15 13:55 37
  FMT_API static constexpr const char right_padding_shifts[5] = {0, 31, 0, 1,
f8deb5b9 Poul Sander 2022-01-15 13:55 38
                                                                 0};
f8deb5b9 Poul Sander 2022-01-15 13:55 39
  FMT_API static constexpr const unsigned prefixes[4] = {0, 0, 0x1000000u | '+',
f8deb5b9 Poul Sander 2022-01-15 13:55 40
                                                         0x1000000u | ' '};
f8deb5b9 Poul Sander 2022-01-15 13:55 41
};
f8deb5b9 Poul Sander 2022-01-15 13:55 42
f8deb5b9 Poul Sander 2022-01-15 13:55 43
#ifdef FMT_SHARED
f8deb5b9 Poul Sander 2022-01-15 13:55 44
// Required for -flto, -fivisibility=hidden and -shared to work
f8deb5b9 Poul Sander 2022-01-15 13:55 45
extern template struct basic_data<void>;
f8deb5b9 Poul Sander 2022-01-15 13:55 46
#endif
f8deb5b9 Poul Sander 2022-01-15 13:55 47
f8deb5b9 Poul Sander 2022-01-15 13:55 48
#if __cplusplus < 201703L
f8deb5b9 Poul Sander 2022-01-15 13:55 49
// DEPRECATED! These are here only for ABI compatiblity.
f8deb5b9 Poul Sander 2022-01-15 13:55 50
template <typename T> constexpr const char basic_data<T>::digits[][2];
f8deb5b9 Poul Sander 2022-01-15 13:55 51
template <typename T> constexpr const char basic_data<T>::hex_digits[];
f8deb5b9 Poul Sander 2022-01-15 13:55 52
template <typename T> constexpr const char basic_data<T>::signs[];
f8deb5b9 Poul Sander 2022-01-15 13:55 53
template <typename T> constexpr const char basic_data<T>::left_padding_shifts[];
f8deb5b9 Poul Sander 2022-01-15 13:55 54
template <typename T>
f8deb5b9 Poul Sander 2022-01-15 13:55 55
constexpr const char basic_data<T>::right_padding_shifts[];
f8deb5b9 Poul Sander 2022-01-15 13:55 56
template <typename T> constexpr const unsigned basic_data<T>::prefixes[];
f8deb5b9 Poul Sander 2022-01-15 13:55 57
#endif
f8deb5b9 Poul Sander 2022-01-15 13:55 58
f8deb5b9 Poul Sander 2022-01-15 13:55 59
template <typename T>
f8deb5b9 Poul Sander 2022-01-15 13:55 60
int format_float(char* buf, std::size_t size, const char* format, int precision,
f8deb5b9 Poul Sander 2022-01-15 13:55 61
                 T value) {
f8deb5b9 Poul Sander 2022-01-15 13:55 62
#ifdef FMT_FUZZ
f8deb5b9 Poul Sander 2022-01-15 13:55 63
  if (precision > 100000)
f8deb5b9 Poul Sander 2022-01-15 13:55 64
    throw std::runtime_error(
f8deb5b9 Poul Sander 2022-01-15 13:55 65
        "fuzz mode - avoid large allocation inside snprintf");
f8deb5b9 Poul Sander 2022-01-15 13:55 66
#endif
f8deb5b9 Poul Sander 2022-01-15 13:55 67
  // Suppress the warning about nonliteral format string.
f8deb5b9 Poul Sander 2022-01-15 13:55 68
  int (*snprintf_ptr)(char*, size_t, const char*, ...) = FMT_SNPRINTF;
f8deb5b9 Poul Sander 2022-01-15 13:55 69
  return precision < 0 ? snprintf_ptr(buf, size, format, value)
f8deb5b9 Poul Sander 2022-01-15 13:55 70
                       : snprintf_ptr(buf, size, format, precision, value);
f8deb5b9 Poul Sander 2022-01-15 13:55 71
}
f8deb5b9 Poul Sander 2022-01-15 13:55 72
f8deb5b9 Poul Sander 2022-01-15 13:55 73
template FMT_API dragonbox::decimal_fp<float> dragonbox::to_decimal(float x)
f8deb5b9 Poul Sander 2022-01-15 13:55 74
    FMT_NOEXCEPT;
f8deb5b9 Poul Sander 2022-01-15 13:55 75
template FMT_API dragonbox::decimal_fp<double> dragonbox::to_decimal(double x)
f8deb5b9 Poul Sander 2022-01-15 13:55 76
    FMT_NOEXCEPT;
f8deb5b9 Poul Sander 2022-01-15 13:55 77
}  // namespace detail
f8deb5b9 Poul Sander 2022-01-15 13:55 78
f8deb5b9 Poul Sander 2022-01-15 13:55 79
// Workaround a bug in MSVC2013 that prevents instantiation of format_float.
f8deb5b9 Poul Sander 2022-01-15 13:55 80
int (*instantiate_format_float)(double, int, detail::float_specs,
f8deb5b9 Poul Sander 2022-01-15 13:55 81
                                detail::buffer<char>&) = detail::format_float;
f8deb5b9 Poul Sander 2022-01-15 13:55 82
f8deb5b9 Poul Sander 2022-01-15 13:55 83
#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
f8deb5b9 Poul Sander 2022-01-15 13:55 84
template FMT_API detail::locale_ref::locale_ref(const std::locale& loc);
f8deb5b9 Poul Sander 2022-01-15 13:55 85
template FMT_API std::locale detail::locale_ref::get<std::locale>() const;
f8deb5b9 Poul Sander 2022-01-15 13:55 86
#endif
f8deb5b9 Poul Sander 2022-01-15 13:55 87
f8deb5b9 Poul Sander 2022-01-15 13:55 88
// Explicit instantiations for char.
f8deb5b9 Poul Sander 2022-01-15 13:55 89
f8deb5b9 Poul Sander 2022-01-15 13:55 90
template FMT_API auto detail::thousands_sep_impl(locale_ref)
f8deb5b9 Poul Sander 2022-01-15 13:55 91
    -> thousands_sep_result<char>;
f8deb5b9 Poul Sander 2022-01-15 13:55 92
template FMT_API char detail::decimal_point_impl(locale_ref);
f8deb5b9 Poul Sander 2022-01-15 13:55 93
f8deb5b9 Poul Sander 2022-01-15 13:55 94
template FMT_API void detail::buffer<char>::append(const char*, const char*);
f8deb5b9 Poul Sander 2022-01-15 13:55 95
f8deb5b9 Poul Sander 2022-01-15 13:55 96
// DEPRECATED!
f8deb5b9 Poul Sander 2022-01-15 13:55 97
// There is no correspondent extern template in format.h because of
f8deb5b9 Poul Sander 2022-01-15 13:55 98
// incompatibility between clang and gcc (#2377).
f8deb5b9 Poul Sander 2022-01-15 13:55 99
template FMT_API void detail::vformat_to(
f8deb5b9 Poul Sander 2022-01-15 13:55 100
    detail::buffer<char>&, string_view,
f8deb5b9 Poul Sander 2022-01-15 13:55 101
    basic_format_args<FMT_BUFFER_CONTEXT(char)>, detail::locale_ref);
f8deb5b9 Poul Sander 2022-01-15 13:55 102
f8deb5b9 Poul Sander 2022-01-15 13:55 103
template FMT_API int detail::snprintf_float(double, int, detail::float_specs,
f8deb5b9 Poul Sander 2022-01-15 13:55 104
                                            detail::buffer<char>&);
f8deb5b9 Poul Sander 2022-01-15 13:55 105
template FMT_API int detail::snprintf_float(long double, int,
f8deb5b9 Poul Sander 2022-01-15 13:55 106
                                            detail::float_specs,
f8deb5b9 Poul Sander 2022-01-15 13:55 107
                                            detail::buffer<char>&);
f8deb5b9 Poul Sander 2022-01-15 13:55 108
template FMT_API int detail::format_float(double, int, detail::float_specs,
f8deb5b9 Poul Sander 2022-01-15 13:55 109
                                          detail::buffer<char>&);
f8deb5b9 Poul Sander 2022-01-15 13:55 110
template FMT_API int detail::format_float(long double, int, detail::float_specs,
f8deb5b9 Poul Sander 2022-01-15 13:55 111
                                          detail::buffer<char>&);
f8deb5b9 Poul Sander 2022-01-15 13:55 112
f8deb5b9 Poul Sander 2022-01-15 13:55 113
// Explicit instantiations for wchar_t.
f8deb5b9 Poul Sander 2022-01-15 13:55 114
f8deb5b9 Poul Sander 2022-01-15 13:55 115
template FMT_API auto detail::thousands_sep_impl(locale_ref)
f8deb5b9 Poul Sander 2022-01-15 13:55 116
    -> thousands_sep_result<wchar_t>;
f8deb5b9 Poul Sander 2022-01-15 13:55 117
template FMT_API wchar_t detail::decimal_point_impl(locale_ref);
f8deb5b9 Poul Sander 2022-01-15 13:55 118
f8deb5b9 Poul Sander 2022-01-15 13:55 119
template FMT_API void detail::buffer<wchar_t>::append(const wchar_t*,
f8deb5b9 Poul Sander 2022-01-15 13:55 120
                                                      const wchar_t*);
f8deb5b9 Poul Sander 2022-01-15 13:55 121
f8deb5b9 Poul Sander 2022-01-15 13:55 122
template struct detail::basic_data<void>;
f8deb5b9 Poul Sander 2022-01-15 13:55 123
f8deb5b9 Poul Sander 2022-01-15 13:55 124
FMT_END_NAMESPACE
1970-01-01 00:00 125