How to best deal with Windows' 16-bit wchar_t ugliness?

后端 未结 2 357
暗喜
暗喜 2020-12-20 01:37

I\'m writing a wrapper layer to be used with mingw which provides the application with a virtual UTF-8 environment. Functions which deal with filenames are wrappers which co

2条回答
  •  天命终不由人
    2020-12-20 01:54

    I'd do something like #4, but don't generate any output until you're sure the input is valid.

    • mbrtowc should decode the entire character. If it's outside the BMP, then output the high surrogate and store the low surrogate in the mbstate_t.
    • wcrtomb should store high surrogates in the mbstate_t, then output all 4 UTF-8 bytes if the character is valid.

提交回复
热议问题