大小写不敏感的字符串比较函数

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
}

大小写不敏感的字符串比较函数》上有1条评论

  1. fake birkin bag

    Hi! I could have sworn I’ve been to yoir blog before but after going through a
    few 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!

    回复

发表评论

电子邮件地址不会被公开。 必填项已用*标注

This site uses Akismet to reduce spam. Learn how your comment data is processed.