From f0fd06f92c8b1c601ae0ff7e509ed4145480821c Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 4 Apr 2006 23:38:09 +0000 Subject: [PATCH] add ConvertCodepageToWString, ConvertACPToUTF8 change ConvertWstringToACP -> ConvertWstringToCodepage --- stepmania/src/RageUtil.cpp | 27 ++++++++++++++++++++++++--- stepmania/src/RageUtil.h | 4 +++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/stepmania/src/RageUtil.cpp b/stepmania/src/RageUtil.cpp index a720757113..2ef0cc5c92 100644 --- a/stepmania/src/RageUtil.cpp +++ b/stepmania/src/RageUtil.cpp @@ -279,12 +279,12 @@ RString werr_ssprintf( int err, const char *fmt, ...) return s += ssprintf( " (%s)", text.c_str() ); } -RString ConvertWstringToACP( wstring s ) +RString ConvertWstringToCodepage( wstring s, int iCodePage ) { if( s.empty() ) return RString(); - int iBytes = WideCharToMultiByte( CP_ACP, 0, s.data(), s.size(), + int iBytes = WideCharToMultiByte( iCodePage, 0, s.data(), s.size(), NULL, 0, NULL, FALSE ); ASSERT_M( iBytes > 0, werr_ssprintf( GetLastError(), "WideCharToMultiByte" ).c_str() ); @@ -298,7 +298,28 @@ RString ConvertWstringToACP( wstring s ) RString ConvertUTF8ToACP( const RString &s ) { - return ConvertWstringToACP( RStringToWstring(s) ); + return ConvertWstringToCodepage( RStringToWstring(s), CP_ACP ); +} + +wstring ConvertCodepageToWString( RString s, int iCodePage ) +{ + if( s.empty() ) + return wstring(); + + int iBytes = MultiByteToWideChar( iCodePage, 0, s.data(), s.size(), NULL, 0 ); + ASSERT_M( iBytes > 0, werr_ssprintf( GetLastError(), "MultiByteToWideChar" ).c_str() ); + + wchar_t *pTemp = new wchar_t[iBytes]; + MultiByteToWideChar( CP_ACP, 0, s.data(), s.size(), pTemp, iBytes ); + wstring sRet( pTemp, iBytes ); + delete [] pTemp; + + return sRet; +} + +RString ConvertACPToUTF8( const RString &s ) +{ + return WStringToRString( ConvertCodepageToWString(s, CP_ACP) ); } #endif diff --git a/stepmania/src/RageUtil.h b/stepmania/src/RageUtil.h index f11039ab1e..7354eb4197 100644 --- a/stepmania/src/RageUtil.h +++ b/stepmania/src/RageUtil.h @@ -260,8 +260,10 @@ RString vssprintf( const char *fmt, va_list argList ); #ifdef WIN32 RString hr_ssprintf( int hr, const char *fmt, ...); RString werr_ssprintf( int err, const char *fmt, ...); -RString ConvertWstringToACP( wstring s ); +RString ConvertWstringToCodepage( wstring s, int iCodePage ); RString ConvertUTF8ToACP( const RString &s ); +wstring ConvertCodepageToWString( RString s, int iCodePage ); +RString ConvertACPToUTF8( const RString &s ); #endif /*