Cross-platform strings (and Unicode) in C++

前端 未结 4 1101
半阙折子戏
半阙折子戏 2020-12-25 08:35

So I\'ve finally gotten back to my main task - porting a rather large C++ project from Windows to the Mac.

Straight away I\'ve been hit by the problem where wchar_t

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-25 09:15

    I tend to use UTF-8 as the internal representation. You only lose string length checking, with isn't really useful anyways. For Windows API conversion, I use my own Win32 conversion functions I devised here. As Mac and linux are (for the most part standard UTF-8-aware, no need to convert anything there). Free bonuses you get:

    1. use plain old std::string.
    2. byte-wise network/stream transport.
    3. For most languages, nice memory footprint.
    4. For more functionality: utf8cpp

提交回复
热议问题