sftrabbit / CppPatterns-Patterns

A repository of modern C++ patterns curated by the community.
Creative Commons Zero v1.0 Universal
1.43k stars 223 forks source link

std::string and utf-8 #36

Closed e12e closed 9 years ago

e12e commented 9 years ago

Hi,

as a newcomer to c++, I'm still a bit confused on the status of unicode in the standard, so a sample showing a recommended method of working with utf-8/unicode strings would be appreciated. Things like getting the length (in code-points), reversing a string and/or working with left-to-right vs right-to-left.

As far as I've been able to figure out, one still needs to reach outside of std:: for proper string handling, either using boost or qt?

sftrabbit commented 9 years ago

You're right - the C++ standard's support for Unicode is a little lacklustre. There's not much more you can do than specify the encoding of a string literal (with u8"...", u"...", and U"..."), so you would have to venture out into non-standard libraries. C++ Samples doesn't provide samples for non-standard libraries (at least yet), but I completely agree that it would be nice to at least be pointed in the right direction. I will have a think about this!

thecoshman commented 9 years ago

I suspect this would be going a bit too in-depth into the realms of Unicode for you, but Ogonek is a maturing library for dealing Unicode in modern C++