How can I embed unicode string constants in a source file?

前端 未结 3 1560
一向
一向 2020-12-09 05:33

I\'m writing some unit tests which are going to verify our handling of various resources that use other character sets apart from the normal latin alphabet: Cyrilic, Hebrew

3条回答
  •  不知归路
    2020-12-09 06:14

    A tedious but portable way is to build your strings using numeric escape codes. For example:

    wchar_t *string = L"דונדארןמע";
    

    becomes:

    wchar_t *string = "\x05d3\x05d5\x05e0\x05d3\x05d0\x05e8\x05df\x05de\x05e2";
    

    You have to convert all your Unicode characters to numeric escapes. That way your source code becomes encoding-independent.

    You can use online tools for conversion, such as this one. It outputs the JavaScript escape format \uXXXX, so just search & replace \u with \x to get the C format.

提交回复
热议问题