Esperar UTF8

Una aplicación adecuadamente internacionalizada no asumirá nada sobre el número de bytes en un carácter. Eso significa que no debe usar aritmética de punteros para avanzar sobre los caracteres en una cadena, y significa que no debe usar std::string o funciones estándar de C como strlen() porque asumen lo mismo.

Sin embargo, probablemente ya evite matrices char* simples y aritmética de punteros usando std::string, por lo que sólo necesita comenzar a usar Glib::ustring en su lugar. Consulte el capítulo Conceptos básicos acerca de Glib::ustring.

25.3.1. Glib::ustring y std::iostreams

Unfortunately, the integration with the standard iostreams is not completely foolproof. gtkmm converts Glib::ustrings to a locale-specific encoding (which usually is not UTF-8) if you output them to an ostream with operator<<. Likewise, retrieving Glib::ustrings from istream with operator>> causes a conversion in the opposite direction. But this scheme breaks down if you go through a std::string, e.g. by inputting text from a stream to a std::string and then implicitly converting it to a Glib::ustring. If the string contained non-ASCII characters and the current locale is not UTF-8 encoded, the result is a corrupted Glib::ustring. You can work around this with a manual conversion. For instance, to retrieve the std::string from a ostringstream:

std::locale::global(std::locale("")); // Set the global locale to the user's preferred locale.
                                      // Usually unnecessary here, because Glib::init()
                                      // or Gtk::Application::create() does it for you.
std::ostringstream output;
output << percentage << " % done";