On Tue, Sep 2, 2008 at 8:07 PM, Waqar Malik <[EMAIL PROTECTED]> 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 protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to