?
Danke euch beiden. Artchi leider hab ich inzwischen schon meine eigene Version geschrieben.
Braunstein der Link ist zwar nicht schlecht, aber hat mich doch noch etwas an Arbeit gekostet, da ich das so nicht übernehmen konnte. Aber trotzdem danke, habe es ja hinbekommen
Meine Version von widen:
String ToGString( const char* src, size_t size, const std::locale& loc )
{
# ifdef UNICODE
//Unicode -> String is of type wchar_t
String res( size, 0 );
mbstate_t state;
char* pCNext;
wchar_t* pWNext;
typedef std::codecvt< wchar_t, char, mbstate_t > codecvt;
const codecvt& fac = std::use_facet< codecvt >( loc );
fac.in( state, src, src + size, pCNext, &res[ 0 ], &res[ 0 ] + size, pWNext );
return res;
# else
//No unicode -> String is of type char
return String( src );
# endif
}
Meine Version von narrow:
String ToGString( const wchar_t* src, size_t size, const std::locale& loc )
{
# ifdef UNICODE
//Unicode -> String is of type wchar_t
return String( src );
# else
//No unicode -> String is of type char
String res( size, 0 );
mbstate_t state;
char* pCNext;
wchar_t* pWNext;
typedef std::codecvt< wchar_t, char, mbstate_t > codecvt;
const codecvt& fac = std::use_facet< codecvt >( loc );
fac.out( state, src, src + size, pWNext, &res[ 0 ], &res[ 0 ] + size, pCNext );
return res;
# endif
}
String ist ein typedef das je nach unicode oder nicht einfach ein std::string oder std::wstring ist. GString heißt es nicht wegen _dem_ G-String, sondern steht für generic string