This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: [PATCH/RFA] Fix ctype table and isblank
- From: Wizards' Guild <wizardsguild at earthlink dot net>
- To: newlib at sourceware dot org, newlib at sourceware dot org
- Date: Wed, 8 Apr 2009 14:21:16 -0400 (EDT)
- Subject: Re: [PATCH/RFA] Fix ctype table and isblank
- Reply-to: Wizards' Guild <wizardsguild at earthlink dot net>
Folks,
Here's my lunch hour thought... to avoid widening the ctype table:
For those characters that are alpha but not upper- or lowercase, mark them in the new tables both _U|_L. Existing code will continue to work because nothing in the 00..7F range is marked like this. Then, if the extended tables are supported, modify isupper and islower to do a more specific check:
#define isalpha(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&(_U|_L))
#define isupper(c) (((__ctype_ptr__)[(unsigned)((c)+1)]&(_U|_L))==_U)
#define islower(c) (((__ctype_ptr__)[(unsigned)((c)+1)]&(_U|_L))==_L)
The penalty for this extra check should be very small; it can often be absorbed into the branch test in practical usage. If the extended tables are not supported, the extra test is unnecessary but functionally harmless.
After studying the iswXX behavior some more, I am convinced that Corinna's revised isblank (with the hardcoded tab test) proposal is indeed correct. Of course it must go in a gcc-specific macro; other compilers would presumably get the library version always.
Mike
---
Mike Burgess
Avanex Corporation