CLI11 icon indicating copy to clipboard operation
CLI11 copied to clipboard

widen convert faild in Windows

Open TianZerL opened this issue 1 year ago • 3 comments

If the input filename is unicode(at least with Chinese) and use CLI::ExistingFile to check it, which will call widen_impl indirectly, the line return std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>>().from_bytes(str, str + str_size); failed in Windows.

PS D:\temp\ac> .\ac_cli.exe '.\read - 副本.jpg'
terminate called after throwing an instance of 'std::range_error'
  what():  wstring_convert::from_bytes

I'm using Windows 11 and C++17 standard, and this happend in both VS2022 and MinGW64 gcc 14.1.0.

if I disable CLI11_HAS_CODECVT, the std::mbsrtowcs will fail too.

TianZerL avatar May 18 '24 17:05 TianZerL

Any possibility you could write a failing test in the test cases and add in a PR?

phlptp avatar May 20 '24 19:05 phlptp

@phlptp I think I found the problem. In the Chinese version of Windows, the default encoding for the terminal is GBK (page 936), while CLI11 uses it as utf8, so the convert failed.

Does CLI11 have plans to support local 8-bit encoding?

TianZerL avatar May 21 '24 04:05 TianZerL

If someone knows how to fix it, we could. Don't use Windows or local encodings, or know how to test local encodings in CI.

henryiii avatar Jun 15 '24 03:06 henryiii