Use Encoder instead of Encoding in CsvParser#2106
Open
Rob-Hague wants to merge 3 commits intoJoshClose:masterfrom
Open
Use Encoder instead of Encoding in CsvParser#2106Rob-Hague wants to merge 3 commits intoJoshClose:masterfrom
Rob-Hague wants to merge 3 commits intoJoshClose:masterfrom
Conversation
This improves the ByteCount logic when consuming surrogate characters because the Encoder maintains state across calls. Previously the default behaviour was that the Encoding would return the byte count having replaced the surrogate character with U+FFFD REPLACEMENT CHARACTER because on its own a surrogate character is invalid. For example, when reading the UTF-16 surrogate pair \uD83D\uDE17 corresponding to the Unicode character U+1F617, the (UTF-8) ByteCount would be 6 (the byte count of the sequence \uFFFD\uFFFD) instead of the correct value of 4 UTF-8 bytes.
An encoder with a custom EncoderReplacementFallback could easily require
a larger buffer, for example if its replacement string is "{LONG REPLACEMENT STRING}".
So the upper-bound of 16 bytes is not correct. Note that in this case
CsvParser.ByteCount would be nonsensical for input requiring the fallback, and
configuration.Encoding probably does not match the actual encoding, e.g we are reading
from a UTF-16 byte stream containing non-ASCII characters and we have set
configuration.Encoding to ASCII.
Nevertheless the safeguard is more sensible to have than not.
Owner
|
I'm going to wait on this for now. I believe the SIMD code will completely change how this works. I will be counting blocks of bytes at a time instead of single characters. |
# Conflicts: # src/CsvHelper/CsvParser.cs
Owner
|
I'm thinking of leaving counting bytes and chars up to the user. I believe the user should easily be able to do it themselves once the new parser is released. You will have a |
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.
closes #2088