Skip to content

Read wide strings back from XML archives as UTF-8 - #368

Open
gennaroprota wants to merge 1 commit into
developfrom
fix/xml-iarchive-decodes-wide-strings-as-utf8
Open

Read wide strings back from XML archives as UTF-8#368
gennaroprota wants to merge 1 commit into
developfrom
fix/xml-iarchive-decodes-wide-strings-as-utf8

Conversation

@gennaroprota

Copy link
Copy Markdown
Collaborator

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.

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.
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.

serialization/deserialization of std::wstring with xml archive fails with unicode characters

1 participant