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

JSON parser: Add readJsonString(), refactor all other JSON string functions to use it. #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

LEW21
Copy link

@LEW21 LEW21 commented Aug 30, 2013

While applying Jeremy's comments to my former patch, I've found a better way to organize all that JSON string-related code. This way, all of the 4 jml's json string functions can be refactored to use just one implementation, and also the Unicode-aware parser is much simpler to write:

auto result = growing_buffer{};
readJsonString(context,
[&](char c) {
    result.push_back(c);
},
[&](char16_t c) {
    auto buffer = char[4]{};
    auto end = utf8::unchecked::append(c, buffer);
    for (auto i = buffer; buffer != end; ++i)
        result.push_back(*i);
});
return string{result};

(Updated soa pull request will come later.)

It's written in a way that makes it easy to implement Unicode-supporting
string parser with its help.

Also, refactor all JSON string parsing functions to use it.

Fixes parsing of Unicode escape sequences.
@LEW21
Copy link
Author

LEW21 commented Aug 30, 2013

Ah, almost forgotten. JSON's Unicode escape sequences support only UTF-16, and that's why I'm using UTF-16 here, and not 32bit codepoints. To escape non-BMP chars, two consecutive escape sequences (like \u1234\u5678) are used.

This fact makes it a bit harder to write good Unicode-aware parser than I've written in the pull request description. Still, I'll write it.

(And the current soa's parser also does not support non-BMP characters. It would be a nightmare to add them to its spaghetti code...)

jeremybarnes added a commit that referenced this pull request Jul 3, 2014
…-on-missing-directory

scanFiles no longer throws an exception if the directory doesn't exist (PLAT-567)
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.

1 participant