| 17104 | std::is_same<NumberType, binary_char_t>::value, |
| 17105 | int > = 0 > |
| 17106 | void dump_integer(NumberType x) |
| 17107 | { |
| 17108 | static constexpr std::array<std::array<char, 2>, 100> digits_to_99 |
| 17109 | { |
| 17110 | { |
| 17111 | {{'0', '0'}}, {{'0', '1'}}, {{'0', '2'}}, {{'0', '3'}}, {{'0', '4'}}, {{'0', '5'}}, {{'0', '6'}}, {{'0', '7'}}, {{'0', '8'}}, {{'0', '9'}}, |
| 17112 | {{'1', '0'}}, {{'1', '1'}}, {{'1', '2'}}, {{'1', '3'}}, {{'1', '4'}}, {{'1', '5'}}, {{'1', '6'}}, {{'1', '7'}}, {{'1', '8'}}, {{'1', '9'}}, |
| 17113 | {{'2', '0'}}, {{'2', '1'}}, {{'2', '2'}}, {{'2', '3'}}, {{'2', '4'}}, {{'2', '5'}}, {{'2', '6'}}, {{'2', '7'}}, {{'2', '8'}}, {{'2', '9'}}, |
| 17114 | {{'3', '0'}}, {{'3', '1'}}, {{'3', '2'}}, {{'3', '3'}}, {{'3', '4'}}, {{'3', '5'}}, {{'3', '6'}}, {{'3', '7'}}, {{'3', '8'}}, {{'3', '9'}}, |
| 17115 | {{'4', '0'}}, {{'4', '1'}}, {{'4', '2'}}, {{'4', '3'}}, {{'4', '4'}}, {{'4', '5'}}, {{'4', '6'}}, {{'4', '7'}}, {{'4', '8'}}, {{'4', '9'}}, |
| 17116 | {{'5', '0'}}, {{'5', '1'}}, {{'5', '2'}}, {{'5', '3'}}, {{'5', '4'}}, {{'5', '5'}}, {{'5', '6'}}, {{'5', '7'}}, {{'5', '8'}}, {{'5', '9'}}, |
| 17117 | {{'6', '0'}}, {{'6', '1'}}, {{'6', '2'}}, {{'6', '3'}}, {{'6', '4'}}, {{'6', '5'}}, {{'6', '6'}}, {{'6', '7'}}, {{'6', '8'}}, {{'6', '9'}}, |
| 17118 | {{'7', '0'}}, {{'7', '1'}}, {{'7', '2'}}, {{'7', '3'}}, {{'7', '4'}}, {{'7', '5'}}, {{'7', '6'}}, {{'7', '7'}}, {{'7', '8'}}, {{'7', '9'}}, |
| 17119 | {{'8', '0'}}, {{'8', '1'}}, {{'8', '2'}}, {{'8', '3'}}, {{'8', '4'}}, {{'8', '5'}}, {{'8', '6'}}, {{'8', '7'}}, {{'8', '8'}}, {{'8', '9'}}, |
| 17120 | {{'9', '0'}}, {{'9', '1'}}, {{'9', '2'}}, {{'9', '3'}}, {{'9', '4'}}, {{'9', '5'}}, {{'9', '6'}}, {{'9', '7'}}, {{'9', '8'}}, {{'9', '9'}}, |
| 17121 | } |
| 17122 | }; |
| 17123 | |
| 17124 | // special case for "0" |
| 17125 | if (x == 0) |
| 17126 | { |
| 17127 | o->write_character('0'); |
| 17128 | return; |
| 17129 | } |
| 17130 | |
| 17131 | // use a pointer to fill the buffer |
| 17132 | auto buffer_ptr = number_buffer.begin(); // NOLINT(llvm-qualified-auto,readability-qualified-auto,cppcoreguidelines-pro-type-vararg,hicpp-vararg) |
| 17133 | |
| 17134 | const bool is_negative = std::is_signed<NumberType>::value && !(x >= 0); // see issue #755 |
| 17135 | number_unsigned_t abs_value; |
| 17136 | |
| 17137 | unsigned int n_chars{}; |
| 17138 | |
| 17139 | if (is_negative) |
| 17140 | { |
| 17141 | *buffer_ptr = '-'; |
| 17142 | abs_value = remove_sign(static_cast<number_integer_t>(x)); |
| 17143 | |
| 17144 | // account one more byte for the minus sign |
| 17145 | n_chars = 1 + count_digits(abs_value); |
| 17146 | } |
| 17147 | else |
| 17148 | { |
| 17149 | abs_value = static_cast<number_unsigned_t>(x); |
| 17150 | n_chars = count_digits(abs_value); |
| 17151 | } |
| 17152 | |
| 17153 | // spare 1 byte for '\0' |
| 17154 | JSON_ASSERT(n_chars < number_buffer.size() - 1); |
| 17155 | |
| 17156 | // jump to the end to generate the string from backward |
| 17157 | // so we later avoid reversing the result |
| 17158 | buffer_ptr += n_chars; |
| 17159 | |
| 17160 | // Fast int2ascii implementation inspired by "Fastware" talk by Andrei Alexandrescu |
| 17161 | // See: https://www.youtube.com/watch?v=o4-CwDo2zpg |
| 17162 | while (abs_value >= 100) |
| 17163 | { |
no test coverage detected