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?



On 11/27/03 10:31 AM, Jim Hamilton didst favor us with:

> On Nov 27, 2003, at 1:41 AM, Tom Becker wrote:
>
>> Good point, but in MacRoman only the control characters are
>> unprintable, so
>> a very simple test will at least produce something where you can tell
>> what
>> it is:
>>
>> void Print(FourCharCode id)
>> {
>> if (id >= 0x20202020)
>> printf("%.4s", (char*)&id);
>> else
>> printf("0x%08x", id);
>> }
>>
>
> I can break that!
>
> Print(0x30004142);
>
> would be rendered as "0".
>
> I think we've shown that this is a complex problem. OTOH, there aren't
> THAT many ASCII codes to memorize, and if you're looking for a couple
> of _particular_ FourCharCode values, you can learn their hex
> representations...

*sigh* So much discussion over this. So I'll add my $0.02. LOL

I use CreateTypeStringWithOSType() to convert a FourCharCode to a CFString.
Available in 10.1 or later. See CarbonEvents.h.

FourCharCodes are nothing more than way to specify and view a UInt32 in a
more human-friendly format. It can contain *any* four bytes, so no matter
what you do, there is always the possibility that you can't interpret a
FourCharCode as a readable string of bytes (and hence finding one which
breaks any attempt to "print" is not hard). Any normal FourCharCode will
consist of four bytes which can be viewed as MacRoman characters, primarily
because MacRoman assigns the most characters to values between 0 and 255 and
the whole point of a FourCharCode is to have four bytes you can read as
characters. However, there is nothing to prevent the occurrence of "bad"
FourCharCodes either created intentionally or due to bugs in software. I
recall someone asking me some time back why there were only two characters
in the type and creator of a file he viewed in File Buddy. It turned out
that two of the bytes in each were 0.

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

References: 
 >Re: How do I output FourCharCode variable as text? (From: Jim Hamilton <email@hidden>)



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.