Skip to content

C++ 20: Use UTF-16 Paths and Resource URLs - #12327

Merged
Jon Thysell (jonthysell) merged 9 commits into
microsoft:mainfrom
NickGerleman:utf16-cpp20
Nov 7, 2023
Merged

Jon Thysell (jonthysell) merged 9 commits into
microsoft:mainfrom
NickGerleman:utf16-cpp20

Conversation

@NickGerleman

@NickGerleman Nick Gerleman (NickGerleman) commented Nov 1, 2023 •

Copy link
Copy Markdown
Contributor
  1. Both WinRT and std::filesystem use system-native UTF-16 paths on Windows. Defaulting to UTF16 lets us avoid conversion until needed, and fixes some instances of round-tripping between formats.
  2. We rely on path.u8string() to return a Unicode representation of a path, but that API in C++ 20 returns std::u8string which is incompatible with every other existing utf-8 API. path.string() may convert to system codepage instead.
  3. This makes coroutine usage more efficient when using IAsyncOperation<winrt::hstring>, the pattern to replace std::future<std::string> usage mechanically.
Microsoft Reviewers: Open in CodeFlow

1. Both WinRT and std::filesystem use system-native UTF-16 paths on Windows. Defaulting to UTF16 lets us avoid conversion until needed, and fixes some instances of round-tripping between formats.
2. We rely on `path.u8string()` to return a Unicode representation of a path, but that API in C++ 20 returns `std::u8string` which is incompatible with every other existing utf-8 API. `path.string()` may convert to system codepage instead.
3. This makes coroutine usage more efficient when using `IAsyncOperation<winrt::hstring>`, the pattern to replace `std::future<std::string>` usage mechanically.

`std::filesystem::path` internally uses Windows native UTF-16 path. We use `u8string()` to convert to UTF-8.
@NickGerleman
Nick Gerleman (NickGerleman) marked this pull request as ready for review November 1, 2023 10:46
@NickGerleman Nick Gerleman (NickGerleman) changed the title C++ 20: Use UTF-16 Paths and URLs C++ 20: Use UTF-16 Paths and Resource URLs Nov 2, 2023

@jonthysell Jon Thysell (jonthysell) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jonthysell
Jon Thysell (jonthysell) merged commit 9b93d7b into microsoft:main Nov 7, 2023
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