I've written a small function for converting CEGUI::String to std::string dependend on the Codepage - so your umlauts are converted too!
The disadvantage of this function:
it depends on the ICU library ( http://icu.sf.net )
The advantage:
it is portable (since ICU is availible for *nix, too)
Code: Select all
#include "unicode/ucnv.h"
#include <vector>
std::string CEGUIToASCII(const CEGUI::String& cestr)
{
UConverter *ceguiconv = NULL, *asciiconv = NULL;
UErrorCode status = U_ZERO_ERROR;
std::string result;
if (cestr.size() == 0) return result;
asciiconv = ucnv_open(NULL, &status);
ceguiconv = ucnv_open("utf-8", &status);
if (U_SUCCESS(status))
{
int32_t sourcelen = cestr.utf8_stream_len();
const char* source = cestr.c_str();
const char* sourcelimit = source + sourcelen;
int32_t targetlen = UCNV_GET_MAX_BYTES_FOR_STRING(cestr.length() , ucnv_getMaxCharSize(asciiconv) );
std::vector<char> tmp(targetlen + 1);
char* target = &tmp[0];
char* targetlimit = target + targetlen;
ucnv_convertEx(asciiconv,ceguiconv,&target,targetlimit,&source,sourcelimit,
NULL,NULL,NULL,NULL,true,true,&status);
if ( U_SUCCESS(status) )
result = std::string(tmp.begin(),tmp.end());
else
result = "Error while converting string";
}
else
result = "Error setting up the converters";
if (asciiconv) ucnv_close(asciiconv);
if (ceguiconv) ucnv_close(ceguiconv);
return result;
};