C++WinRT does not correctly handles Chinese characters using Windows.Foundation.Uri
peter li
6
Reputation points
I have a uri with Chinese character and query string that needs to be parsed with Windows.Foundation.Uri
. Using C++WinRT, it always returns me an empty result. But equivalent C# code does returns me expected result.
I have tried changing the file encoding to either UTF-8
and UTF-8 BOM
, nothing worked.
With C++WinRT, create a C++WinRT console application:
winrt::Windows::Foundation::Uri uri{ LR"(myapp://open?file="C:/我.txt")" };
winrt::Windows::Foundation::WwwFormUrlDecoder parsed{ uri.Query() };
for (auto entry : parsed)
{
std::wcout << entry.Name().data() << L'\t' << entry.Value().data() << L'\n';
}
With C#, create a UWP project:
var uri = new Uri("myapp://open?file=\"C:/我.txt\"");
var parsed = new WwwFormUrlDecoder(uri.Query);
foreach (var entry in parsed)
{
Debug.WriteLine(entry);
}
C# gives me expected result:
C++ gives me empty result:
Sign in to answer