-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Added emitUTF8 setting. #1045
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
Added emitUTF8 setting. #1045
Conversation
src/lib_json/json_writer.cpp
Outdated
@@ -267,7 +267,7 @@ static String toHex16Bit(unsigned int x) { | |||
return result; | |||
} | |||
|
|||
static String valueToQuotedStringN(const char* value, unsigned length) { | |||
static String valueToQuotedStringN(const char* value, unsigned length, bool emitUTF8 = false ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to overload it instead of rewriting it, I guess?
etc, use it outside the method
if (_emitUTF8) {
....
} else {
valueToQuotedStringN(value, length);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to use the escaping of the tabs, newlines etc. in the first part of the function and then either write the UTF-8 characters or unicode escape them in the second part. Perhaps I should split the function into those separate pieces? What's your view?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually prefer it as is. There's nothing wrong with the default argument usage here, especially since most of the downsides of default arguments don't apply to static methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm glad that you're all considering binary compatibility. Thank you.
Yes, internal "statics" are hidden from the public API, so either way is fine with me.
This change is a nice idea.
In addition, it's better to write some testcases to test this change. |
I'll add some tests this evening. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to add this feature, thanks for writing this up. If you can address my feedback, I'll look at submitting it.
src/lib_json/json_writer.cpp
Outdated
@@ -267,7 +267,7 @@ static String toHex16Bit(unsigned int x) { | |||
return result; | |||
} | |||
|
|||
static String valueToQuotedStringN(const char* value, unsigned length) { | |||
static String valueToQuotedStringN(const char* value, unsigned length, bool emitUTF8 = false ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually prefer it as is. There's nothing wrong with the default argument usage here, especially since most of the downsides of default arguments don't apply to static methods.
Great! Thanks! |
Good for it. |
why didn't we add a description to |
Thanks so much for adding in this functionality, it's desperately needed. But I'm still baffled why it's opt-in?
UTF-8 encoding absolutely should be the defaut. |
This PR adds a new setting 'emitUTF8' which avoids unicode escaping the emitted JSON.