split windows-specific stuff out of RageUtil
This commit is contained in:
@@ -260,81 +260,6 @@ RString vssprintf( const char *fmt, va_list argList )
|
||||
return sStr;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#ifdef _XBOX
|
||||
# include <D3DX8Core.h>
|
||||
#else
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
RString werr_ssprintf( int err, const char *fmt, ...)
|
||||
{
|
||||
char buf[1024] = "";
|
||||
#ifndef _XBOX
|
||||
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
0, err, 0, buf, sizeof(buf), NULL);
|
||||
#endif
|
||||
|
||||
/* Why is FormatMessage returning text ending with \r\n? */
|
||||
RString text = buf;
|
||||
text.Replace( "\n", "" );
|
||||
text.Replace( "\r", " " ); /* foo\r\nbar -> foo bar */
|
||||
TrimRight( text ); /* "foo\r\n" -> "foo" */
|
||||
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
RString s = vssprintf( fmt, va );
|
||||
va_end(va);
|
||||
|
||||
return s += ssprintf( " (%s)", text.c_str() );
|
||||
}
|
||||
|
||||
RString ConvertWstringToCodepage( wstring s, int iCodePage )
|
||||
{
|
||||
if( s.empty() )
|
||||
return RString();
|
||||
|
||||
int iBytes = WideCharToMultiByte( iCodePage, 0, s.data(), s.size(),
|
||||
NULL, 0, NULL, FALSE );
|
||||
ASSERT_M( iBytes > 0, werr_ssprintf( GetLastError(), "WideCharToMultiByte" ).c_str() );
|
||||
|
||||
RString ret;
|
||||
WideCharToMultiByte( CP_ACP, 0, s.data(), s.size(),
|
||||
ret.GetBuffer( iBytes ), iBytes, NULL, FALSE );
|
||||
ret.ReleaseBuffer( iBytes );
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
RString ConvertUTF8ToACP( const RString &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( iCodePage, 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
|
||||
|
||||
/* ISO-639-1 codes: http://www.loc.gov/standards/iso639-2/langcodes.html
|
||||
* native forms: http://people.w3.org/rishida/names/languages.html
|
||||
* We don't use 3-letter codes, so we don't bother supporting them. */
|
||||
|
||||
Reference in New Issue
Block a user