* 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
This commit is contained in:
David Elliott
2004-01-22 06:18:06 +00:00
parent 2b030203c5
commit 9e888492a6

View File

@@ -15,16 +15,39 @@
#import <Foundation/NSString.h> #import <Foundation/NSString.h>
#include "wx/string.h" #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 // Return an autoreleased NSString
inline NSString* wxNSStringWithWxString(const wxString &wxstring) 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()]; return [NSString stringWithCString: wxstring.c_str() length:wxstring.Len()];
#endif // wxUSE_UNICODE
} }
// Intialize an NSString which has already been allocated // Intialize an NSString which has already been allocated
inline NSString* wxInitNSStringWithWxString(NSString *nsstring, const wxString &wxstring) 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()]; 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__ #endif // __WX_COCOA_STRING_H__