2003-06-13 17:09:21 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/cocoa/string.h
|
|
|
|
// Purpose: String conversion methods
|
|
|
|
// Author: David Elliott
|
|
|
|
// Modified by:
|
|
|
|
// Created: 2003/04/13
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 2003 David Elliott
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
2003-06-13 17:09:21 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef __WX_COCOA_STRING_H__
|
|
|
|
#define __WX_COCOA_STRING_H__
|
|
|
|
|
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
#include "wx/string.h"
|
|
|
|
|
2004-01-22 01:18:06 -05:00
|
|
|
// 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.
|
|
|
|
|
2003-06-13 17:09:21 -04:00
|
|
|
// Return an autoreleased NSString
|
|
|
|
inline NSString* wxNSStringWithWxString(const wxString &wxstring)
|
|
|
|
{
|
2004-01-22 01:18:06 -05:00
|
|
|
#if wxUSE_UNICODE
|
2007-08-21 05:40:36 -04:00
|
|
|
return [NSString stringWithUTF8String: wxstring.utf8_str()];
|
2004-01-22 01:18:06 -05:00
|
|
|
#else
|
2003-06-13 17:09:21 -04:00
|
|
|
return [NSString stringWithCString: wxstring.c_str() length:wxstring.Len()];
|
2004-01-22 01:18:06 -05:00
|
|
|
#endif // wxUSE_UNICODE
|
2003-06-13 17:09:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Intialize an NSString which has already been allocated
|
|
|
|
inline NSString* wxInitNSStringWithWxString(NSString *nsstring, const wxString &wxstring)
|
|
|
|
{
|
2004-01-22 01:18:06 -05:00
|
|
|
#if wxUSE_UNICODE
|
2007-08-21 05:40:36 -04:00
|
|
|
return [nsstring initWithUTF8String: wxstring.utf8_str()];
|
2004-01-22 01:18:06 -05:00
|
|
|
#else
|
2003-06-13 17:09:21 -04:00
|
|
|
return [nsstring initWithCString: wxstring.c_str() length:wxstring.Len()];
|
2004-01-22 01:18:06 -05:00
|
|
|
#endif // wxUSE_UNICODE
|
|
|
|
}
|
|
|
|
|
|
|
|
inline wxString wxStringWithNSString(NSString *nsstring)
|
|
|
|
{
|
|
|
|
#if wxUSE_UNICODE
|
2007-08-21 05:40:36 -04:00
|
|
|
return wxString::FromUTF8([nsstring UTF8String]);
|
2004-01-22 01:18:06 -05:00
|
|
|
#else
|
|
|
|
return wxString([nsstring lossyCString]);
|
|
|
|
#endif // wxUSE_UNICODE
|
2003-06-13 17:09:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __WX_COCOA_STRING_H__
|