18 stream << std::boolalpha << value << std::noboolalpha;
23 if (std::isnan(value))
27 else if (std::isinf(value))
37 double intPart = 1e16;
38 const double fractPart = std::modf(value, &intPart);
40 if (fractPart == 0.0 && intPart > -1e16 && intPart < 1e16)
42 stream << std::fixed << std::setprecision(1) << value << std::defaultfloat;
46 stream << std::setprecision(15) << value << std::defaultfloat;
53 static const std::array<char, 17> HEX = {
"0123456789abcdef"};
55 (void)stream.put(
'"');
56 for (
char character : value)
58 if (character ==
'\\' || character ==
'"')
60 (void)stream.put(
'\\');
61 (void)stream.put(character);
63 else if (character ==
'\b')
65 (void)stream.put(
'\\');
66 (void)stream.put(
'b');
68 else if (character ==
'\f')
70 (void)stream.put(
'\\');
71 (void)stream.put(
'f');
73 else if (character ==
'\n')
75 (void)stream.put(
'\\');
76 (void)stream.put(
'n');
78 else if (character ==
'\r')
80 (void)stream.put(
'\\');
81 (void)stream.put(
'r');
83 else if (character ==
'\t')
85 (void)stream.put(
'\\');
86 (void)stream.put(
't');
90 const unsigned int characterInt =
91 static_cast<unsigned int>(std::char_traits<char>::to_int_type(character));
92 if (characterInt <= 0x1F)
94 (void)stream.put(
'\\');
95 (void)stream.put(
'u');
96 (void)stream.put(
'0');
97 (void)stream.put(
'0');
98 (void)stream.put(HEX[(characterInt >> 4U) & 0xFU]);
99 (void)stream.put(HEX[characterInt & 0xFU]);
103 (void)stream.put(character);
107 (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, StringView value)