WChars, Encodings, Standards and Portability

后端 未结 4 1695
遇见更好的自我
遇见更好的自我 2020-11-22 09:11

The following may not qualify as a SO question; if it is out of bounds, please feel free to tell me to go away. The question here is basically, \"Do I understand the C stand

4条回答
  •  没有蜡笔的小新
    2020-11-22 09:58

    I would avoid the wchar_t type because it's platform-dependent (not "serializable" by your definition): UTF-16 on Windows and UTF-32 on most Unix-like systems. Instead, use the char16_t and/or char32_t types from C++0x/C1x. (If you don't have a new compiler, typedef them as uint16_t and uint32_t for now.)

    DO define functions to convert between UTF-8, UTF-16, and UTF-32 functions.

    DON'T write overloaded narrow/wide versions of every string function like the Windows API did with -A and -W. Pick one preferred encoding to use internally, and stick to it. For things that need a different encoding, convert as necessary.

提交回复
热议问题