17 stream << std::boolalpha << value << std::noboolalpha;
22 if (std::isnan(value))
26 else if (std::isinf(value))
36 double intPart = 1e16;
37 const double fractPart = std::modf(value, &intPart);
39 if (fractPart == 0.0 && intPart > -1e16 && intPart < 1e16)
41 stream << std::fixed << std::setprecision(1) << value << std::defaultfloat;
45 stream << std::setprecision(15) << value << std::defaultfloat;
52 static const std::array<char, 17> HEX = {
"0123456789abcdef"};
54 (void)stream.put(
'"');
55 for (
char character : value)
57 if (character ==
'\\' || character ==
'"')
59 (void)stream.put(
'\\');
60 (void)stream.put(character);
62 else if (character ==
'\b')
64 (void)stream.put(
'\\');
65 (void)stream.put(
'b');
67 else if (character ==
'\f')
69 (void)stream.put(
'\\');
70 (void)stream.put(
'f');
72 else if (character ==
'\n')
74 (void)stream.put(
'\\');
75 (void)stream.put(
'n');
77 else if (character ==
'\r')
79 (void)stream.put(
'\\');
80 (void)stream.put(
'r');
82 else if (character ==
'\t')
84 (void)stream.put(
'\\');
85 (void)stream.put(
't');
89 const unsigned int characterInt =
90 static_cast<unsigned int>(std::char_traits<char>::to_int_type(character));
91 if (characterInt <= 0x1F)
93 (void)stream.put(
'\\');
94 (void)stream.put(
'u');
95 (void)stream.put(
'0');
96 (void)stream.put(
'0');
97 (void)stream.put(HEX[(characterInt >> 4U) & 0xFU]);
98 (void)stream.put(HEX[characterInt & 0xFU]);
102 (void)stream.put(character);
106 (void)stream.put(
'"');
static void encodeFloatingPoint(std::ostream &stream, double value)
static void encodeNull(std::ostream &stream)
static void encodeBool(std::ostream &stream, bool value)
static void encodeString(std::ostream &stream, std::string_view value)