Read wide strings back from XML archives as UTF-8 - #368
Open
gennaroprota wants to merge 1 commit into
Open
Conversation
The XML output archive writes a `std::wstring` as UTF-8, through `mb_from_wchar`, but the input archive decoded it with `std::mbrtowc`, which follows the current locale. This means anything outside ASCII came back wrong, each byte having turned into one character. The text and binary archives were never affected, as they write the characters unchanged. The input archive now decodes with `wchar_from_mb`, the counterpart of the writer's `mb_from_wchar`. That iterator in turn had to stop taking a partial conversion for a failure: it fills its input buffer without regard to character boundaries, so a multibyte character can straddle the end, and the bytes left over are already carried to the next round. A conversion which really fails now throws instead of asserting. Fixes #298.
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.
The XML output archive writes a
std::wstringas UTF-8, throughmb_from_wchar, but the input archive decoded it withstd::mbrtowc, which follows the current locale. This means anything outside ASCII came back wrong, each byte having turned into one character. The text and binary archives were never affected, as they write the characters unchanged.The input archive now decodes with
wchar_from_mb, the counterpart of the writer'smb_from_wchar. That iterator in turn had to stop taking a partial conversion for a failure: it fills its input buffer without regard to character boundaries, so a multibyte character can straddle the end, and the bytes left over are already carried to the next round. A conversion which really fails now throws instead of asserting.Fixes #298.