Add YYJSON_WRITE_LOWERCASE_HEX flag for \uXXXX escape case#264
Merged
Conversation
Both RFC 8259 §7 forms are valid, but the rest of the JSON ecosystem (ext/json, Python json, Node.js JSON.stringify, Go encoding/json, Ruby json, Jackson, RapidJSON) defaults to lowercase hex. yyjson is the conspicuous outlier with uppercase. Callers shipping yyjson output to those consumers currently need a post-processing pass for byte-equality. This flag selects a second pre-computed 512-byte hex table at the top of each writer call; the per-byte hot loop is identical. No performance impact on either path. Implementation: - Add esc_hex_char_table_lower next to the existing uppercase table - get_hex_table_with_flag() returns the right table based on flag - write_str() takes hex_table as parameter; threaded through the 5 write driver functions that call it - The U+FFFD replacement in the invalid-UTF-8 error path now reads its 4 hex bytes from hex_table too (two byte_copy_2 instead of one byte_copy_4 from a hardcoded rep v32; same total output, error path is not perf-critical)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #264 +/- ##
==========================================
- Coverage 98.50% 98.49% -0.02%
==========================================
Files 2 2
Lines 9040 7699 -1341
==========================================
- Hits 8905 7583 -1322
+ Misses 135 116 -19
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Owner
|
Thanks! This flag does seem useful, let's merge it first. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #263.
Both RFC 8259 §7 forms are valid, but several widely-used JSON encoders default to lowercase hex: PHP
ext/json, Pythonjson, Node.jsJSON.stringify(when it emits\ufor control chars), Goencoding/json. yyjson defaults to uppercase. Callers shipping yyjson output to those consumers currently need a post-processing pass for byte-equality.This flag selects a second pre-computed 512-byte hex table at the top of each writer call; the per-byte hot loop is identical. No performance impact on either path.
Functional test on the patched build:
Builds clean (CMake Release, gcc 14, no new warnings).