• 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: NSString really Unicode?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSString really Unicode?


  • Subject: Re: NSString really Unicode?
  • From: "James J. Merkel" <email@hidden>
  • Date: Fri, 12 Mar 2004 08:47:24 -0800

I was using core foundation string encoding because there was a note in the NSString documentation that said the NSString encodings were only a subset of the encodings available (or something to that effect). But I see that the core foundation encodings aren't compatible with the NSString encodings. However, I tried various NSString encodings and I get similar results. Specifically, I tried NSUnicodeStringEncoding, but this produces Chinese characters (or Japanese, I'm not sure which).

This is a digital camera raw image file. I'm reading metadata in the file. There is no BOM for the file, and the strings aren't marked with a BOM, however the file is basically little endian format.

This brings up another question -- what I'm really looking at are key-value pairs in the file. What I would like to to is use the key to look up a string in a Localizable.strings file. However, I notice that if I use UTF-16 encoding for the Localizable.strings file, the strings are big endian format. Is there a way of making this file little endian format?

Thanks for the help.
Jim Merkel



On Mar 12, 2004, at 7:53 AM, Shawn Erickson wrote:


On Mar 12, 2004, at 7:16 AM, James J. Merkel wrote:

Here are the applicable lines of code:

fread(valueBuf, sizeof(char), valueLength, ifp);
valueString = [[NSString alloc]initWithBytes:valueBuf length:valueLength encoding:kCFStringEncodingASCII];
NSLog(@"the value string = %d\n", [valueString intValue]);

For the encoding, I have tried various string encodings in core foundation.

A dump from HexEdit of the applicable part of the file being read is:

31 00 30 00 36 00 34 00 35 00 30 00 37 00 33 00
39 00 35 00 00 00

This is a Unix time(c) style format string - seconds since 1/01/1970 - encoded in Unicode.
The NSLog above just prints out 1 -- the first digit of the string.

Looking at the data it is an ASCII character followed by a null (zero). So the C string is terminated after the first character if you attempt to read it in with ASCII encoding which is a 1 byte per character encoding.

Why are you using kCFStringEncoding... flags instead of the NS based flags for encoding.

Did you try NSUnicodeStringEncoding?

Anyway this looks like a byte flipped encoding without a BOM it may have a problem reading it as a result... what is the source of this file? What exact encoding was used to create it?

-Shawn
_______________________________________________
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.


  • Follow-Ups:
    • Re: NSString really Unicode?
      • From: Ali Ozer <email@hidden>
    • Re: NSString really Unicode?
      • From: Dustin Voss <email@hidden>
References: 
 >NSString really Unicode? (From: "James J. Merkel" <email@hidden>)
 >Re: NSString really Unicode? (From: "M. Uli Kusterer" <email@hidden>)
 >Re: NSString really Unicode? (From: "James J. Merkel" <email@hidden>)
 >Re: NSString really Unicode? (From: Allan Odgaard <email@hidden>)
 >Re: NSString really Unicode? (From: "James J. Merkel" <email@hidden>)
 >Re: NSString really Unicode? (From: Shawn Erickson <email@hidden>)

  • Prev by Date: Re: Odd binding issue
  • Next by Date: [ANN] blue:tec Localization Suite
  • Previous by thread: Re: NSString really Unicode?
  • Next by thread: Re: NSString really Unicode?
  • Index(es):
    • Date
    • Thread