microsoft / wil

Windows Implementation Library
MIT License
2.58k stars 236 forks source link

Add UTF-8 configuration option for wil::ResultException::what() #238

Open reupen opened 2 years ago

reupen commented 2 years ago

Hi,

Am I right in thinking that wil::ResultException::what() returns an ANSI-encoded string?

It'd be useful to be able to configure the library to return a UTF-8 string instead.

Thanks

CookiePLMonster commented 2 years ago

Alternately - .whatW() that returns an Unicode string? Might be a viable approach too.

reupen commented 2 years ago

Yes, that would be useful as well. For me personally, UTF-8 would be simpler as I'm already generally dealing with it and so could avoid special handling for wil::ResultException.

vonj commented 2 years ago

Not all UTF8 strings can be represented in UCS2, though?

5 maj 2022 kl. 23:22 skrev Reupen Shah @.***>:

 Yes, that would be useful as well. For me personally, UTF-8 would be simpler as I'm already generally dealing with it and so could avoid special handling for wil::ResultException.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.

CookiePLMonster commented 2 years ago

Not all UTF8 strings can be represented in UCS2, though? 5 maj 2022 kl. 23:22 skrev Reupen Shah @.***>:  Yes, that would be useful as well. For me personally, UTF-8 would be simpler as I'm already generally dealing with it and so could avoid special handling for wil::ResultException. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.

Windows uses UTF-16, not UCS-2.

vonj commented 2 years ago

Right. I might have thought about the fact that fileNAMES in Windows can contain data which is not valid UTF16.

https://github.com/nodejs/node/issues/23735

lanyizi commented 2 years ago

IIRC all standard c++ exceptions' what() uses encoding of "current locale's code page", which normally happens to be ANSI code page. For example, std::system_error with std::system_category on MSVC, or std::filesystem::filesystem_error.