Skip to content

Fix wstring conversion on Windows #1479

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

Merged
merged 1 commit into from
Jun 16, 2025

Conversation

AnyOldName3
Copy link
Contributor

On most Unices, wchar_t is 32 bits and typically holds UCS4 characters, which are big enough for any Unicode code point.

On Windows, wchar_t is 16 bits and typically holds UTF-16 code units, which sometimes need to be used in pairs. This is because Windows introduced wchar_t before UCS4, UTF-8 and UTF-16 were invented, originally using them for UCS2 characters back when all of Unicode fit in sixteen bits.

That meant that the existing string conversion code, which assumed std::wstring was a fixed-width encoding, would only work on Windows for the first 55295 code points (where UCS2 and UTF-16 were compatible), so anything outside the basic multilingual plane wouldn't work.

I'll push a test app to vsgExamples in a minute or two. I've confirmed that this fixes everything on Windows and doesn't break anything on Ubuntu.

On most Unices, wchar_t is 32 bits and typically holds UCS4 characters, which are big enough for any Unicode code point.

On Windows, wchar_t is 16 bits and typically holds UTF-16 code units, which sometimes need to be used in pairs.
This is because Windows introduced wchar_t before UCS4, UTF-8 and UTF-16 were invented, originally using them for UCS2 characters back when all of Unicode fit in sixteen bits.

That meant that the existing string conversion code, which assumed std::wstring was a fixed-width encoding, would only work on Windows for the first 55295 code points (where UCS2 and UTF-16 were compatible), so anything outside the basic multilingual plane wouldn't work.
@AnyOldName3
Copy link
Contributor Author

I've also confirmed this works with MSYS2 as that's an edge case.

@robertosfield robertosfield merged commit 7093200 into vsg-dev:master Jun 16, 2025
8 checks passed
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.

2 participants