Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include unicode formatting support for JSON escapes #2880

Merged
merged 5 commits into from
Aug 31, 2024

Conversation

mikee47
Copy link
Contributor

@mikee47 mikee47 commented Aug 30, 2024

This PR improves on #2875 for JSON string formatting, updating the escapeControls function to handle unicode escaping correctly.

The check for valid UTF8 has been removed. That's erroneous and got in there because of my lack of understanding about how JSON is encoded. It's fundamentally UNICODE, so characters outside of standard ASCII must all be encoded using \uNNNN escapes. That ensures output is always valid JSON, even if string input is garbage.

The escapeControls function has a options parameter which makes it a lot more useful for various escaping requirements. This is also more efficient as the input string requires only two passes for both escaping and quoting: the first pass establishes the new string length, the buffer is re-allocated then the modified string produced.

Copy link

what-the-diff bot commented Aug 30, 2024

PR Summary

  • Introduction of a New Parameter unicode in Certain Functions
    A new parameter named 'unicode' has been added to some specific functions in Formatter.cpp and Formatter.h.

  • Improved escape Function in Json.cpp
    The Json::escape function in Json.cpp has been enhanced. Now it uses the escapeControls function together with the unicode parameter set to true. This allows better control and manipulation of unicode characters in JSON formatting to ensure correct and clean data interchange.

@mikee47 mikee47 changed the title Feature/json unicode Include unicode formatting support for JSON escapes Aug 30, 2024
@mikee47 mikee47 marked this pull request as draft August 31, 2024 09:18
@mikee47 mikee47 marked this pull request as ready for review August 31, 2024 09:51
@mikee47 mikee47 force-pushed the feature/json-unicode branch from e8c2dee to 38c46e7 Compare August 31, 2024 10:43
@slaff slaff added this to the 6.0.0 milestone Aug 31, 2024
@slaff slaff merged commit 6caca47 into SmingHub:develop Aug 31, 2024
46 checks passed
@mikee47 mikee47 deleted the feature/json-unicode branch August 31, 2024 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants