Is there an STL and UTF-8 friendly C++ Wrapper for

2019-01-22 18:57发布

I need a good Unicode library for C++. I need:

  1. Transformations in a Unicode sensitive way. For example sort all strings in a case insensitive way and get their first characters for index. Convert various Unicode strings to upper and to lower case. Split text at a reasonable position -- words that would work for Chinese and Japanese as well.
  2. Formatting numbers, dates in locale sensitive way (should be thread safe).
  3. Transparent support of UTF-8 (primary internal representation).

As far as I know the best library is ICU. However, I can't find normal developer friendly API documentation with examples. Also as far as I see, it is not too friendly with modern C++ design, work with STL and so on. Like this:

std::string msg;
unistring umsg.from_utf8(msg);
unistring::word_iterator wi;
for(wi=umsg.words().begin(),n=0;wi!=usmg.words().wi_end(),n<10;++wi,++n) 
  ;
msg=umsg.substr(umsg.words().begin(),wi).to_utf8();
cout<<_("Five 10 words are ")<<msg;

Is there a good STL friendly ICU wrapper released under Open Source license? Preferred is a license permissive like MIT or Boost, but others, like LGPLv2 compatible, are OK as well.

Is there another high quality library similar to ICU?

Platform: Unix/POSIX, Windows support is not required.

Edit: unfortunately I wasn't logged in, so I can't make accept an answer. I have attached the answer by myself.

3条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-01-22 19:12

The wxWidgets GUI toolkit has some rather nice string classes and unicode support. You don't need to build/use GUI classes if you don't want to. See here for details.

查看更多
Bombasti
4楼-- · 2019-01-22 19:30

This question was asked quite a long time before by myself. There was no such library.

So I had written C++ friendly Boost.Locale library that wraps ICU.

Edit Now part of Boost: see Boost.Locale documentation

查看更多
登录 后发表回答