From 003cb4baa656526e390b48e43ad24ffee273f484 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Mon, 20 Mar 2006 07:56:18 +0000 Subject: [PATCH] OS X text converter. --- stepmania/src/RageUtil_CharConversions.cpp | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/stepmania/src/RageUtil_CharConversions.cpp b/stepmania/src/RageUtil_CharConversions.cpp index bc338a9c56..188daa542b 100644 --- a/stepmania/src/RageUtil_CharConversions.cpp +++ b/stepmania/src/RageUtil_CharConversions.cpp @@ -90,6 +90,37 @@ static bool AttemptEnglishConversion( RString &txt ) { return ConvertFromCharset static bool AttemptKoreanConversion( RString &txt ) { return ConvertFromCharset( txt, "CP949" ); } static bool AttemptJapaneseConversion( RString &txt ) { return ConvertFromCharset( txt, "CP932" ); } +#elif defined(MACOSX) +#include + +static bool ConvertFromCP( RString &txt, int cp ) +{ + CFStringEncoding encoding = CFStringConvertWindowsCodepageToEncoding( cp ); + + if( encoding == kCFStringEncodingInvalidId ) + return false; + + CFStringRef old = CFStringCreateWithCString( kCFAllocatorDefault, txt, encoding ); + + if( old == NULL ) + return false; + const size_t size = CFStringGetMaximumSizeForEncoding( CFStringGetLength(old), kCFStringEncodingUTF8 ); + + char *buf = new char[size]; + if( !CFStringGetCString(old, buf, size, kCFStringEncodingUTF8) ) + { + delete[] buf; + return false; + } + txt = buf; + delete[] buf; + return true; +} + +static bool AttemptEnglishConversion( RString &txt ) { return ConvertFromCP( txt, 1252 ); } +static bool AttemptKoreanConversion( RString &txt ) { return ConvertFromCP( txt, 949 ); } +static bool AttemptJapaneseConversion( RString &txt ) { return ConvertFromCP( txt, 932 ); } + #else /* No converters are available, so all fail--we only accept UTF-8. */