Support unicode surrogate pairs
As per the latest JSON standard, unicode pairs can be used to encode UTF-16 characters in UTF-8 JSON. This release adds support for surrogate pairs.
const char* json = R"("\uD83D\uDE00\uD83C\uDF40😀🍀\uD83D\uDE00")"; // 😀🍀😀🍀😀
std::string val;
expect(!glz::read_json(val, json));
expect(val == "😀🍀😀🍀😀");Float max write precision
Adds the ability to set the maximum write precision for floating point values. Wrappers are also provided to locally turn this feature on and off. This reduces the size of the JSON output for floating point numbers when the precision isn't needed on output and is especially useful for std::float128_t. See documentation at max-float-precision.md
Examples:
double pi = std::numbers::pi_v<double>;
std::string json_double = glz::write_json(pi);
constexpr glz::opts options{.float_max_write_precision = glz::float_precision::float32};
std::string json_float = glz::write<options>(pi);
expect(json_float == glz::write_json(std::numbers::pi_v<float>));
std::vector<double> double_array{pi, 2 * pi};
json_double = glz::write_json(double_array);
json_float = glz::write<options>(double_array);
expect(json_float == glz::write_json(std::array{std::numbers::pi_v<float>, 2 * std::numbers::pi_v<float>}));Improvements
- Using 256 byte tables for invalid JSON safety by @stephenberry in #937
- Faster escaped unicode handling
Full Changelog: v2.5.3...v2.5.4