Skip to content

Fix wstring conversion on Windows#1479

Merged
robertosfield merged 1 commit into
vsg-dev:masterfrom
AnyOldName3:windows-unicode-fixes
Jun 16, 2025
Merged

Fix wstring conversion on Windows#1479
robertosfield merged 1 commit into
vsg-dev:masterfrom
AnyOldName3:windows-unicode-fixes

Conversation

@AnyOldName3

Copy link
Copy Markdown
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
Copy Markdown
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