]> git.saurik.com Git - wxWidgets.git/blame - include/wx/cocoa/string.h
using Run of base class
[wxWidgets.git] / include / wx / cocoa / string.h
CommitLineData
724ebdde
DE
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/cocoa/string.h
3// Purpose: String conversion methods
4// Author: David Elliott
5// Modified by:
6// Created: 2003/04/13
724ebdde 7// Copyright: (c) 2003 David Elliott
65571936 8// Licence: wxWindows licence
724ebdde
DE
9///////////////////////////////////////////////////////////////////////////////
10
11#ifndef __WX_COCOA_STRING_H__
12#define __WX_COCOA_STRING_H__
13
14#import <Foundation/NSString.h>
15#include "wx/string.h"
16
9e888492
DE
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.
22
724ebdde
DE
23// Return an autoreleased NSString
24inline NSString* wxNSStringWithWxString(const wxString &wxstring)
25{
9e888492 26#if wxUSE_UNICODE
fbbdc7bf 27 return [NSString stringWithUTF8String: wxstring.utf8_str()];
9e888492 28#else
724ebdde 29 return [NSString stringWithCString: wxstring.c_str() length:wxstring.Len()];
9e888492 30#endif // wxUSE_UNICODE
724ebdde
DE
31}
32
33// Intialize an NSString which has already been allocated
34inline NSString* wxInitNSStringWithWxString(NSString *nsstring, const wxString &wxstring)
35{
9e888492 36#if wxUSE_UNICODE
fbbdc7bf 37 return [nsstring initWithUTF8String: wxstring.utf8_str()];
9e888492 38#else
724ebdde 39 return [nsstring initWithCString: wxstring.c_str() length:wxstring.Len()];
9e888492
DE
40#endif // wxUSE_UNICODE
41}
42
43inline wxString wxStringWithNSString(NSString *nsstring)
44{
45#if wxUSE_UNICODE
cc209a51 46 return wxString::FromUTF8Unchecked([nsstring UTF8String]);
9e888492
DE
47#else
48 return wxString([nsstring lossyCString]);
49#endif // wxUSE_UNICODE
724ebdde
DE
50}
51
52#endif // __WX_COCOA_STRING_H__