]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/cocoa/string.h
Fix a very annoying autorelease pool memory leak.
[wxWidgets.git] / include / wx / cocoa / string.h
index d9dde29d2456a2b967fea9b9181bee496284138f..65112a053a89e2ecd3b49265ed250723d42cb5c6 100644 (file)
@@ -4,7 +4,6 @@
 // Author:      David Elliott
 // Modified by:
 // Created:     2003/04/13
-// RCS-ID:      $Id$
 // Copyright:   (c) 2003 David Elliott
 // Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
 #import <Foundation/NSString.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
 inline NSString* wxNSStringWithWxString(const wxString &wxstring)
 {
+#if wxUSE_UNICODE
+    return [NSString stringWithUTF8String: wxstring.utf8_str()];
+#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.utf8_str()];
+#else
     return [nsstring initWithCString: wxstring.c_str() length:wxstring.Len()];
+#endif // wxUSE_UNICODE
+}
+
+inline wxString wxStringWithNSString(NSString *nsstring)
+{
+#if wxUSE_UNICODE
+    return wxString::FromUTF8Unchecked([nsstring UTF8String]);
+#else
+    return wxString([nsstring lossyCString]);
+#endif // wxUSE_UNICODE
 }
 
 #endif // __WX_COCOA_STRING_H__