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/26/03 11:33 AM, Pete Gontier wrote:
> if (FourCharCodeIsPrintable (fourCharCode))
> printf ("%.4s", &fourCharCode); // as if it were a string
> else
> printf ("%08X", fourCharCode); // hexadecimal
>
> 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.

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've actually used code like this before in applications where IDs were a
mixture of alpha codes and numbers.

Tom

--
Tom Becker "Within C++, there is a much smaller and
Object-Oriented Propeller Head cleaner language struggling to get out."
<email@hidden> -- Bjarne Stroustrup
_______________________________________________
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: Pete Gontier <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.