From 9e888492a618fe6910620736848f73d7ec4b9675 Mon Sep 17 00:00:00 2001 From: David Elliott Date: Thu, 22 Jan 2004 06:18:06 +0000 Subject: [PATCH] * Add Unicode support for wxNSStringWithWxString and wxInitNSStringWithWxString * Add wxStringWithNSString which works for both WC and MB builds git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25288 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/string.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/wx/cocoa/string.h b/include/wx/cocoa/string.h index d9dde29d24..be1067101d 100644 --- a/include/wx/cocoa/string.h +++ b/include/wx/cocoa/string.h @@ -15,16 +15,39 @@ #import #include "wx/string.h" +// FIXME: In unicode mode we are doing the conversion twice. wxString +// converts to UTF-8 and NSString converts from UTF-8. +// One possible optimization is to convert to the wxString internal +// representation which is an unsigned short (unichar) but unfortunately +// there is little documentation on which encoding it uses by default. + // Return an autoreleased NSString inline NSString* wxNSStringWithWxString(const wxString &wxstring) { +#if wxUSE_UNICODE + return [NSString stringWithUTF8String: wxstring.mb_str(wxConvUTF8)]; +#else return [NSString stringWithCString: wxstring.c_str() length:wxstring.Len()]; +#endif // wxUSE_UNICODE } // Intialize an NSString which has already been allocated inline NSString* wxInitNSStringWithWxString(NSString *nsstring, const wxString &wxstring) { +#if wxUSE_UNICODE + return [nsstring initWithUTF8String: wxstring.mb_str(wxConvUTF8)]; +#else return [nsstring initWithCString: wxstring.c_str() length:wxstring.Len()]; +#endif // wxUSE_UNICODE +} + +inline wxString wxStringWithNSString(NSString *nsstring) +{ +#if wxUSE_UNICODE + return wxString([nsstring UTF8String], wxConvUTF8); +#else + return wxString([nsstring lossyCString]); +#endif // wxUSE_UNICODE } #endif // __WX_COCOA_STRING_H__