For UTF-8 support, there is the Glib::ustring class. It is modeled after std::string
but is utf-8 aware,e.g. when you are scanning the string with an iterator. It also has some restrictions, e.g. the iterator is always const
, as replacing a character can change the length of the string and so it can invalidate other iterators.
ustring
does not automatically converts other encodings to utf-8, Glib
library has various conversion functions for this. You can validate whether the string is a valid utf-8 though.
And also, ustring
and std::string
are interchangeable, i.e. ustring
has a cast operator to std::string so you can pass a ustring
as a parameter where an std::string
is expected, and vice versa of course, as ustring
can be constructed from std::string
.