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

skip UTF-8 BOM if present #2079

Merged
merged 1 commit into from Oct 30, 2023
Merged

skip UTF-8 BOM if present #2079

merged 1 commit into from Oct 30, 2023

Conversation

lemire
Copy link
Member

@lemire lemire commented Oct 30, 2023

Currently, if you want to parse a string that might have a BOM, you have to do something like this...

std::string input;   
load(input);
input.reserve(input.size() + simdjson::SIMDJSON_PADDING);   
std::string_view json_string(input);   
if (input.size() >= 3 && 0 == memcmp(input.data(), "\xEF\xBB\xBF", 3)) {    
 json_string.remove_prefix(3);  // Skip UTF-8 BOM.   
}   
parser.iterate(json_string, json_string.max_size());

This PR would simplify the code to...

std::string input;   
load(input);
parser.iterate(input);

@lemire lemire requested a review from anonrig October 30, 2023 15:46
@lemire lemire merged commit 8b2af04 into master Oct 30, 2023
73 checks passed
@lemire lemire deleted the skip_utf8_bom branch October 30, 2023 16:51
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.

None yet

2 participants