• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: utf8 to NSString crasher
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: utf8 to NSString crasher


  • Subject: Re: utf8 to NSString crasher
  • From: "Shawn Erickson" <email@hidden>
  • Date: Wed, 3 Sep 2008 08:27:57 -0700

On Tue, Sep 2, 2008 at 8:07 PM, Waqar Malik <email@hidden> wrote:

> Well I really want to convert wchar_t to NSString, and the only way to
> convert to NSString was to convert to UTF8 apparently wchar_t->utf8 is
> converting correctly.

Who is creating the wchar_t strings? What encoding is being used?

(sorry not sure if and what "default" encoding exists for wchar_t)

If the wchar_t string contains UTF-32 then a more direct conversion to
NSString should be possible (assuming you know byte order or it
contains a BOM) and assuming you target 10.5 and later.

-[NSString initWithData:encoding:] and you can create the data object
using the no copy init method to avoid an unneeded copy of your string
bytes.

NSUTF32StringEncoding
32-bit UTF encoding.
Available in Mac OS X v10.5 and later.

NSUTF32BigEndianStringEncoding
NSUTF32StringEncoding encoding with explicit endianness specified.
Available in Mac OS X v10.5 and later.

NSUTF32LittleEndianStringEncoding
NSUTF32StringEncoding encoding with explicit endianness specified.
Available in Mac OS X v10.5 and later.

...or use CFStringCreateWithBytes if you want to support 10.4 (or
avoid the use of NSData)...

kCFStringEncodingUTF32
An encoding constant that identifies kTextEncodingUnicodeDefault +
kUnicodeUTF32Format encoding.
Available in Mac OS X v10.4 and later.

kCFStringEncodingUTF32BE
An encoding constant that identifies kTextEncodingUnicodeDefault +
kUnicodeUTF32BEFormat encoding. This constant specifies big-endian
byte order.
Available in Mac OS X v10.4 and later.

kCFStringEncodingUTF32LE
An encoding constant that identifies kTextEncodingUnicodeDefault +
kUnicodeUTF32LEFormat encoding. This constant specifies little-endian
byte order.
Available in Mac OS X v10.4 and later.

-Shawn
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >utf8 to NSString crasher (From: Waqar Malik <email@hidden>)

  • Prev by Date: Re: NSInteger
  • Next by Date: Re: [ANN] AppKiDo 0.981, with fixes for Xcode 3
  • Previous by thread: Re: utf8 to NSString crasher
  • Next by thread: Re: utf8 to NSString crasher
  • Index(es):
    • Date
    • Thread