• 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: [SOLVED] Converting wchar_t string to NSString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [SOLVED] Converting wchar_t string to NSString


  • Subject: Re: [SOLVED] Converting wchar_t string to NSString
  • From: David Elliott <email@hidden>
  • Date: Sun, 8 Feb 2004 18:14:48 -0500

On Feb 8, 2004, at 2:19 PM, Andrew Thompson wrote:

On Feb 8, 2004, at 12:06 PM, David Elliott wrote:

No, I do know the difference between encoding and character set. I thought it was clear from my message that I was using the wchar_t type (from Panther and Jaguar) and wcs* functions from Panther using a 4-byte (that is what wchar_t is on OS X after all) Unicode character set.

That's the point I was trying to make :) There's no such thing as a "4-byte Unicode character set". Character sets exist independent of any particular representation on any architecture. Change the last part of your sentence to " 4-byte Unicode character encoding" and we're there. Sorry to be pedantic.


I meant to say that I was using the unicode character set with some 4-byte encoding. Sorry for the confusion. The encoding would be one of UCS-4 or UTF-32 I would imagine. As far as I know there are no other 4-byte unicode encodings (are there?) and the difference between these two only shows up when the high bit is set. The point I was trying to make is that there don't seem to be any functions for converting from any 4-byte unicode encoding to the 2-byte encoding used in (NS|CF)String.

Glen seems to agree in this message:

On Feb 8, 2004, at 5:35 PM, Glen Low wrote:
On Feb 8, 2004, at 12:06 PM, David Elliott wrote:
The problem is in all those encodings listed on Apple's page I didn't see even one that took 4-byte unicode characters in any encoding. Did I just miss it? I've visited those pages quite a few times.

I took a glance and didn't see any either.

So I'm glad two more sets of eyes agree with me then.

On Feb 8, 2004, at 2:19 PM, Andrew Thompson wrote:
On Feb 8, 2004, at 12:06 PM, David Elliott wrote:
Alternatively, I recently found out wxWindows has functions for converting to/from UTF-16 so if NSString can efficiently take that (i.e. without doing another conversion itself) then that would be an option. Right now I'm doing a conversion from wxString (which is using 4-byte wchar_t based strings) to UTF-8 and then to NSString. That involves two conversions when one would be better.

NSString is UTF16 internally, so that should cut your conversions to 1.


Okay, so then I'd use an internal conversion routine that spits out UTF-16 and either [NSString +stringWithCharacters:length:] or [NSString -initWithCharacters:length:].

I also see there is [NSString -initWithCharactersNoCopy:length:freeWhenDone:]. I assume that means I can have the conversion routine malloc the string and then leave NSString to free it.

On the way back I'd use [NSString -getCharacters] and [NSString -length] and pass them to a conversion routine that converts to the wxString format.

Thanks!
-Dave
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Converting Japanese C- string to NSString (From: Darrin Cardani <email@hidden>)
 >Re: Converting Japanese C- string to NSString (From: John Stiles <email@hidden>)
 >Converting wchar_t string to NSString (From: David Elliott <email@hidden>)
 >Re: Converting wchar_t string to NSString (From: Glen Low <email@hidden>)
 >Re: Converting wchar_t string to NSString (From: Andrew Thompson <email@hidden>)
 >Re: Converting wchar_t string to NSString (From: David Elliott <email@hidden>)
 >Re: Converting wchar_t string to NSString (From: Andrew Thompson <email@hidden>)

  • Prev by Date: Re: What can I do with an NSRange in Objective-C?
  • Next by Date: Re: Document App or not?[little ot]
  • Previous by thread: Re: Converting wchar_t string to NSString
  • Next by thread: Re: Converting wchar_t string to NSString
  • Index(es):
    • Date
    • Thread