1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/cocoa/string.h
3 // Purpose: String conversion methods
4 // Author: David Elliott
7 // Copyright: (c) 2003 David Elliott
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef __WX_COCOA_STRING_H__
12 #define __WX_COCOA_STRING_H__
14 #import <Foundation/NSString.h>
15 #include "wx/string.h"
17 // FIXME: In unicode mode we are doing the conversion twice. wxString
18 // converts to UTF-8 and NSString converts from UTF-8.
19 // One possible optimization is to convert to the wxString internal
20 // representation which is an unsigned short (unichar) but unfortunately
21 // there is little documentation on which encoding it uses by default.
23 // Return an autoreleased NSString
24 inline NSString
* wxNSStringWithWxString(const wxString
&wxstring
)
27 return [NSString stringWithUTF8String
: wxstring
.utf8_str()];
29 return [NSString stringWithCString
: wxstring
.c_str() length
:wxstring
.Len()];
30 #endif // wxUSE_UNICODE
33 // Intialize an NSString which has already been allocated
34 inline NSString
* wxInitNSStringWithWxString(NSString
*nsstring
, const wxString
&wxstring
)
37 return [nsstring initWithUTF8String
: wxstring
.utf8_str()];
39 return [nsstring initWithCString
: wxstring
.c_str() length
:wxstring
.Len()];
40 #endif // wxUSE_UNICODE
43 inline wxString
wxStringWithNSString(NSString
*nsstring
)
46 return wxString::FromUTF8Unchecked([nsstring UTF8String
]);
48 return wxString([nsstring lossyCString
]);
49 #endif // wxUSE_UNICODE
52 #endif // __WX_COCOA_STRING_H__