大小写不敏感的字符串比较函数
doom3的源码,大小写不敏感的比较两个字符串,如果相等返回0,s1>s2返回1,s1 精妙吧,哈哈。。
#define INTSIGNBITNOTSET(i) ((~((const unsigned long)(i))) >> 31)
int Icmp( const char *s1, const char *s2 ) {
int c1, c2, d;
do {
c1 = *s1++;
c2 = *s2++;
d = c1 - c2;
while( d ) {
if ( c1 <= 'Z' && c1 >= 'A' ) {
d += ('a' - 'A');
if ( !d ) {
break;
}
}
if ( c2 <= 'Z' && c2 >= 'A' ) {
d -= ('a' - 'A');
if ( !d ) {
break;
}
}
return ( INTSIGNBITNOTSET( d ) << 1 ) - 1;
}
} while( c1 );
return 0; // strings are equal
}
Hi! I could have sworn I've been to yoir blog before but after going through a
ReplyDeletefew of the posts I realized it's new to me.
Anyways, I'm certainly delighted I discovered iit and I'll be bookmarking it and checking back
often!