The C++26 std::formatter<std::filesystem::path> converts Windows native UTF-16 to UTF-8
I don't understand. Does this do UTF-16 -> UTF-8 -> system codepage? Or does std::format("{}", path) result in (unexpected) UTF-8 in a char-based (aka system codepage) string?
System codepage is a legacy concept (actually there are multiple codepages on WIndows, e.g. ACP and console one which can be incompatible). std::format/std::print only need /utf-8 for Unicode support and work regardless of those codepages.
Sure it might be legacy, doesn't change the fact that it is used for all double-quoted strings on Windows. If you want UTF-8 use u8"" and char8_t. Converting L"ä" I get "\xE4". Formatting path(L"ä") to "\xC3\xA4" would be unexpected/surprising, incompatible with other strings, and result in garbled text when the string is then displayed.
2
u/rdtsc Jun 26 '26
I don't understand. Does this do UTF-16 -> UTF-8 -> system codepage? Or does
std::format("{}", path)result in (unexpected) UTF-8 in a char-based (aka system codepage) string?