is their a better way of checking for alpha?
Is this a proper way to test if a char is an alpha or am I dreaming. If it even works I feel like I might be doing something the hard way when there is something easier.
Code:
#define LOWEST_ALPHA 0x41
#define HIGHEST_ALPHA 0x5A
#define LOWEST_CAPS_ALPHA 0x61
#define HIGHEST_CAPS_ALPHA 0x7A
/* 0000 0000 0000 0000 0000 0000 0111 1111 */
#define NON_ASCII_BIT_MASK 0x7F
/* 1000 0000 0000 0000 0000 0000 0000 0000 */
#define ASCII_SIGNED_BIT 0x80000000
/* Clear non ascii bits then set the signed bit */
#define MAKE_SIGNED_ASCII( ch ) \
( ((ch) & NON_ASCII_BIT_MASK ) | ASCII_SIGNED_BIT )
#define IN_ASCII_ALPHA_RANGE( ch ) \
(( ch >= LOWEST_ALPHA && ch <= HIGHEST_ALPHA ) || \
( ch >= LOWEST_CAPS_ALPHA && ch <= HIGHEST_CAPS_ALPHA ))
int isalpha( char ch )
{
int result;
/* Clear non ascii bits then set the signed bit */
if ( IN_ASCII_ALPHA_RANGE( MAKE_SIGNED_ASCII( ch ) ){
return true;
} else {
return false;
}
}
NB: I know of the BSD isalpha() function but my code has to compile on windoze as well.