Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I output FourCharCode variable as text?



>From: Pete Gontier <email@hidden>
>To: Carbon Development <email@hidden>
>
>circa 11/26/03 12:52 PM, John Stiles <email@hidden> wrote:
>
>>> Unfortunately, an exhaustive implementation of FourCharCodeIsPrintable is
>>> non-trivial. You could simplify it at the expense of shunting more cases into
>>> hexadecimal by calling isprint for each byte, which would mean some printable
>>> UTF-8 characters would not be considered printable. If you run into
>>> endianness issues, this code sequence will become more complex.
>
>> I'm going to go out on a limb and say that nobody ever made a
>> four-character-code with UTF8 in it. Or at the very least, maybe
>> somebody did, but you probably won't run across it in your code.
>> MacRoman you should expect to see from time to time (I've used MacRoman
> > in 4CCs myself), but UTF8 seems really dubious.
>
>The point was that FourCharCode is not a string and has no encoding, so you
>can't reliably pass its address to printf as if it were a string. As you
>point out, people type what they think are MacRoman characters into
>FourCharCode values all the time. I don't know enough about UTF8 to say for
>sure, but it would not surprise me to learn that some MacRoman values cause
>the UTF8 parser in Terminal to do weird things.

The four characters in type/creator codes are, by definition, always in MacRoman encoding, and many programs have creator codes that use high-bit MacRoman characters.

I recommend using something like:

FourCharCode fcc = 'What';
CFStringRef fccString = CFStringCreateWithBytes(kCFAllocatorDefault, (UInt8*)&fcc, sizeof(fcc), kCFStringEncodingMacRoman, FALSE);

and then printing fccString with
CFShowStr(fccString);
or handling it otherwise as a CFString.

--
Rainer Brockerhoff <email@hidden>
Belo Horizonte, Brazil
"It's extremely unlucky to be superstitious, for no other reason
than it is always unlucky to be colossally stupid." (Stephen Fry)
Weblog: http://www.brockerhoff.net/bb/viewtopic.php
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.