Unicode std::string class replacement

前端 未结 5 820
滥情空心
滥情空心 2021-02-06 01:18

I\'m looking for suggestions regarding unicode aware std::string library replacements. I have a bunch of code that uses std::string, its iterators etc, and would like to now sup

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-06 01:31

    Asking for "a type like std::string, but for Unicode" is like asking for "a type like unsigned, but for primes." std::string is perfectly capable of storing Unicode, in many encodings - the most generally useful being UTF-8.

    What you need to replace is your iterators, not your storage type. The iterators should iterate over the codepoints of the string rather than the bytes. That is, ++i should advance one codepoint, and *i should return a codepoint (via uint32_t) rather than a char.

提交回复
热议问题