]> git.saurik.com Git - wxWidgets.git/blame - include/wx/cocoa/string.h
Further performance optimizations
[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
7// RCS-ID: $Id$
8// Copyright: (c) 2003 David Elliott
65571936 9// Licence: wxWindows licence
724ebdde
DE
10///////////////////////////////////////////////////////////////////////////////
11
12#ifndef __WX_COCOA_STRING_H__
13#define __WX_COCOA_STRING_H__
14
15#import <Foundation/NSString.h>
16#include "wx/string.h"
17
9e888492
DE
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.
23
724ebdde
DE
24// Return an autoreleased NSString
25inline NSString* wxNSStringWithWxString(const wxString &wxstring)
26{
9e888492 27#if wxUSE_UNICODE
fbbdc7bf 28 return [NSString stringWithUTF8String: wxstring.utf8_str()];
9e888492 29#else
724ebdde 30 return [NSString stringWithCString: wxstring.c_str() length:wxstring.Len()];
9e888492 31#endif // wxUSE_UNICODE
724ebdde
DE
32}
33
34// Intialize an NSString which has already been allocated
35inline NSString* wxInitNSStringWithWxString(NSString *nsstring, const wxString &wxstring)
36{
9e888492 37#if wxUSE_UNICODE
fbbdc7bf 38 return [nsstring initWithUTF8String: wxstring.utf8_str()];
9e888492 39#else
724ebdde 40 return [nsstring initWithCString: wxstring.c_str() length:wxstring.Len()];
9e888492
DE
41#endif // wxUSE_UNICODE
42}
43
44inline wxString wxStringWithNSString(NSString *nsstring)
45{
46#if wxUSE_UNICODE
fbbdc7bf 47 return wxString::FromUTF8([nsstring UTF8String]);
9e888492
DE
48#else
49 return wxString([nsstring lossyCString]);
50#endif // wxUSE_UNICODE
724ebdde
DE
51}
52
53#endif // __WX_COCOA_STRING_H__