string.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. // Copyright: (c) 2003 David Elliott
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef __WX_COCOA_STRING_H__
  11. #define __WX_COCOA_STRING_H__
  12. #import <Foundation/NSString.h>
  13. #include "wx/string.h"
  14. // FIXME: In unicode mode we are doing the conversion twice. wxString
  15. // converts to UTF-8 and NSString converts from UTF-8.
  16. // One possible optimization is to convert to the wxString internal
  17. // representation which is an unsigned short (unichar) but unfortunately
  18. // there is little documentation on which encoding it uses by default.
  19. // Return an autoreleased NSString
  20. inline NSString* wxNSStringWithWxString(const wxString &wxstring)
  21. {
  22. #if wxUSE_UNICODE
  23. return [NSString stringWithUTF8String: wxstring.utf8_str()];
  24. #else
  25. return [NSString stringWithCString: wxstring.c_str() length:wxstring.Len()];
  26. #endif // wxUSE_UNICODE
  27. }
  28. // Intialize an NSString which has already been allocated
  29. inline NSString* wxInitNSStringWithWxString(NSString *nsstring, const wxString &wxstring)
  30. {
  31. #if wxUSE_UNICODE
  32. return [nsstring initWithUTF8String: wxstring.utf8_str()];
  33. #else
  34. return [nsstring initWithCString: wxstring.c_str() length:wxstring.Len()];
  35. #endif // wxUSE_UNICODE
  36. }
  37. inline wxString wxStringWithNSString(NSString *nsstring)
  38. {
  39. #if wxUSE_UNICODE
  40. return wxString::FromUTF8Unchecked([nsstring UTF8String]);
  41. #else
  42. return wxString([nsstring lossyCString]);
  43. #endif // wxUSE_UNICODE
  44. }
  45. #endif // __WX_COCOA_STRING_H__