Konda.eu

C++ - Unicode Strings! Say Goodbye to std::string

No comments

C++ - Unicode Strings! Say Goodbye to std::string

During my years of programming in C++, the biggest pain were probably strings. There is no simple standard cross platform way for Unicode strings. std::string class by itself is also lacking a lot of methods for every day work. Comparing it to C#, Java or any other language is almost useless. Features as starts withends withto lower, to upper, trim and similar are all missing. It has ==, while Java doesn't. Yes, all of the functions above can be easily written with templates but it adds an extra load of work and maintenance, which we all try to avoid.

After a couple of years I finally decided to try ICU - International Components for Unicode. It's a C++ library for Unicode strings. It weights roughly 20MB when shipped with executable, but it's totally worth it. Linux, Apple, Google Chrome and other mayor companies or products use it. All of the above functions are provided and a couple more, all mayor code tables are supported, file access is with already familiar C like interface and as a bonus it's fully integrated with C++ streams.

icu::UnicodeString str = L"Hi ICU with öäüšćž!";
str = str.toLower();
str = str.append(" Foo!   ").trim();

cout << str << endl;

I urge you, give ICU a try!

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.