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