Re: Displaying different languages in an NSTableView
Re: Displaying different languages in an NSTableView
- Subject: Re: Displaying different languages in an NSTableView
- From: Michael James <email@hidden>
- Date: Mon, 14 Oct 2002 06:48:44 -0400
I found a solution to my determining if a string is Unicode problem.
According to the ID3v2 spec, unicode string must be prepended with a
Unicode BOM (Byte Order Mark). This BOM is a 2-byte unicode character
whose value is either 0xFFFE or 0xFEFF (depending on the endianness of
the string). Therefore, I check for the BOM and if it's there than I
use NSUnicodeStringEncoding, otherwise, I use NSASCIIStringEncoding.
For example,
unichar unicodeBOM;
[data getBytes: &unicodeBOM length: 2];
if (unicodeBOM == 0xFFFE || unicodeBOM == 0xFEFF)
{
string = [[NSString alloc] initWithData: data encoding:
NSUnicodeStringEncoding];
}
else
{
string = [[NSString alloc] initWithData: data encoding:
NSASCIIStringEncoding];
}
This works for my ID3 tag parsing (mostly because the spec tells you
what to look for), but it may not work in other situations. As I
understand all Unicode strings are supposed to have that BOM character,
but if you're not dealing with Unicode then none of this helps at all.
Just thought I'd pass this along for those who could use it.
Michael James
email@hidden
On Sunday, October 13, 2002, at 04:38 AM, Ondra Cada wrote:
On Sunday, October 13, 2002, at 08:43 , Michael James wrote:
is there a way to determine if the string you're about to read is
encoded using Unicode, ASCII, or something else?
Generally there is not.
In the specific case of ID3 tags there might be, I dunno: what you
need is a good MP3 format description. It has plain nothing to do with
Cocoa or Carbon, it's the data format.
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
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.