⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 string.c

📁 Netscape NSPR库源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* PL_strncasecmp */PRBool test_014(void){    static struct    {        const char *one;        const char *two;        PRUint32    max;        PRIntn      sign;    } array[] =      {          { (const char *)0, (const char *)0, 0, 0 },          { (const char *)0, (const char *)0, 1, 0 },          { (const char *)0, (const char *)0, 4, 0 },          { (const char *)0, "word", 0, -1 },          { (const char *)0, "word", 1, -1 },          { (const char *)0, "word", 4, -1 },          { "word", (const char *)0, 0, 1 },          { "word", (const char *)0, 1, 1 },          { "word", (const char *)0, 4, 1 },          { "word", "word", 0, 0 },          { "word", "word", 1, 0 },          { "word", "word", 3, 0 },          { "word", "word", 5, 0 },          { "aZYXVUT", "bZYXVUT", 0, 0 },          { "aZYXVUT", "bZYXVUT", 1, -1 },          { "aZYXVUT", "bZYXVUT", 4, -1 },          { "aZYXVUT", "bZYXVUT", 9, -1 },          { "aZYXVUT", "bAAAAAA", 0, 0 },          { "aZYXVUT", "bAAAAAA", 1, -1 },          { "aZYXVUT", "bAAAAAA", 4, -1 },          { "aZYXVUT", "bAAAAAA", 5, -1 },          { "a", "aa", 0, 0 },          { "a", "aa", 1, 0 },          { "a", "aa", 4, -1 },          { "a", "a", 0, 0 },          { "a", "a", 1, 0 },          { "a", "a", 4, 0 },          { "a", "A", 0, 0 },          { "a", "A", 1, 0 },          { "a", "A", 4, 0 },          { "aaaaa", "baaaa", 0, 0 },          { "aaaaa", "baaaa", 1, -1 },          { "aaaaa", "baaaa", 4, -1 },          { "aaaaa", "abaaa", 0, 0 },          { "aaaaa", "abaaa", 1, 0 },          { "aaaaa", "abaaa", 4, -1 },          { "aaaaa", "aabaa", 0, 0 },          { "aaaaa", "aabaa", 1, 0 },          { "aaaaa", "aabaa", 4, -1 },          { "aaaaa", "aaaba", 0, 0 },          { "aaaaa", "aaaba", 1, 0 },          { "aaaaa", "aaaba", 4, -1 },          { "aaaaa", "aaaab", 0, 0 },          { "aaaaa", "aaaab", 1, 0 },          { "aaaaa", "aaaab", 4, 0 },          { "bZYXVUT", "aZYXVUT", 0, 0 },          { "bZYXVUT", "aZYXVUT", 1, 1 },          { "bZYXVUT", "aZYXVUT", 4, 1 },          { "bAAAAAA", "aZYXVUT", 0, 0 },          { "bAAAAAA", "aZYXVUT", 1, 1 },          { "bAAAAAA", "aZYXVUT", 4, 1 },          { "aa", "a", 0, 0 },          { "aa", "a", 1, 0 },          { "aa", "a", 4, 1 },          { "A", "a", 0, 0 },          { "A", "a", 1, 0 },          { "A", "a", 4, 0 },          { "baaaa", "aaaaa", 0, 0 },          { "baaaa", "aaaaa", 1, 1 },          { "baaaa", "aaaaa", 4, 1 },          { "abaaa", "aaaaa", 0, 0 },          { "abaaa", "aaaaa", 1, 0 },          { "abaaa", "aaaaa", 4, 1 },          { "aabaa", "aaaaa", 0, 0 },          { "aabaa", "aaaaa", 1, 0 },          { "aabaa", "aaaaa", 4, 1 },          { "aaaba", "aaaaa", 0, 0 },          { "aaaba", "aaaaa", 1, 0 },          { "aaaba", "aaaaa", 4, 1 },          { "aaaab", "aaaaa", 0, 0 },          { "aaaab", "aaaaa", 1, 0 },          { "aaaab", "aaaaa", 4, 0 },          { "word", "Word", 0, 0 },          { "word", "Word", 1, 0 },          { "word", "Word", 3, 0 },          { "word", "wOrd", 0, 0 },          { "word", "wOrd", 1, 0 },          { "word", "wOrd", 3, 0 },          { "word", "woRd", 0, 0 },          { "word", "woRd", 1, 0 },          { "word", "woRd", 3, 0 },          { "word", "worD", 0, 0 },          { "word", "worD", 1, 0 },          { "word", "worD", 3, 0 },          { "WORD", "wORD", 0, 0 },          { "WORD", "wORD", 1, 0 },          { "WORD", "wORD", 3, 0 },          { "WORD", "WoRD", 0, 0 },          { "WORD", "WoRD", 1, 0 },          { "WORD", "WoRD", 3, 0 },          { "WORD", "WOrD", 0, 0 },          { "WORD", "WOrD", 1, 0 },          { "WORD", "WOrD", 3, 0 },          { "WORD", "WORd", 0, 0 },          { "WORD", "WORd", 1, 0 },          { "WORD", "WORd", 3, 0 }      };    int i;    printf("Test 014 (PL_strncasecmp) ..."); fflush(stdout);    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )    {        PRIntn rv = PL_strncasecmp(array[i].one, array[i].two, array[i].max);        switch( array[i].sign )        {            case -1:                if( rv < 0 ) continue;                break;            case 1:                if( rv > 0 ) continue;                break;            case 0:                if( 0 == rv ) continue;                break;            default:                PR_NOT_REACHED("static data inconsistancy");                break;        }        printf("FAIL %d: %s-%s/%ld -> %d, not %d\n", i,               array[i].one ? array[i].one : "(null)",               array[i].two ? array[i].two : "(null)",               array[i].max, rv, array[i].sign);        return PR_FALSE;    }    printf("PASS\n");    return PR_TRUE;}/* PL_strchr */PRBool test_015(void){    static struct    {        const char *str;        char        chr;        PRBool      ret;        PRUint32    off;    } array[] =      {          { (const char *)0, 'a', PR_FALSE, 0 },          { (const char *)0, '\0', PR_FALSE, 0 },          { "abcdefg", 'a', PR_TRUE, 0 },          { "abcdefg", 'b', PR_TRUE, 1 },          { "abcdefg", 'c', PR_TRUE, 2 },          { "abcdefg", 'd', PR_TRUE, 3 },          { "abcdefg", 'e', PR_TRUE, 4 },          { "abcdefg", 'f', PR_TRUE, 5 },          { "abcdefg", 'g', PR_TRUE, 6 },          { "abcdefg", 'h', PR_FALSE, 0 },          { "abcdefg", '\0', PR_TRUE, 7 },          { "abcdefg", 'A', PR_FALSE, 0 },          { "abcdefg", 'B', PR_FALSE, 0 },          { "abcdefg", 'C', PR_FALSE, 0 },          { "abcdefg", 'D', PR_FALSE, 0 },          { "abcdefg", 'E', PR_FALSE, 0 },          { "abcdefg", 'F', PR_FALSE, 0 },          { "abcdefg", 'G', PR_FALSE, 0 },          { "abcdefg", 'H', PR_FALSE, 0 },          { "abcdefgabcdefg", 'a', PR_TRUE, 0 },          { "abcdefgabcdefg", 'b', PR_TRUE, 1 },          { "abcdefgabcdefg", 'c', PR_TRUE, 2 },          { "abcdefgabcdefg", 'd', PR_TRUE, 3 },          { "abcdefgabcdefg", 'e', PR_TRUE, 4 },          { "abcdefgabcdefg", 'f', PR_TRUE, 5 },          { "abcdefgabcdefg", 'g', PR_TRUE, 6 },          { "abcdefgabcdefg", 'h', PR_FALSE, 0 },          { "abcdefgabcdefg", '\0', PR_TRUE, 14 }      };    int i;    printf("Test 015 (PL_strchr)      ..."); fflush(stdout);    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )    {        char *rv = PL_strchr(array[i].str, array[i].chr);        if( PR_FALSE == array[i].ret )        {            if( (char *)0 != rv )            {                printf("FAIL %d: %s,%c -> %.32s, not zero\n", i, array[i].str,                       array[i].chr, rv);                return PR_FALSE;            }        }        else        {            if( (char *)0 == rv )            {                printf("FAIL %d: %s,%c -> null, not +%lu\n", i, array[i].str,                       array[i].chr, array[i].off);                return PR_FALSE;            }            if( &array[i].str[ array[i].off ] != rv )            {                printf("FAIL %d: %s,%c -> 0x%x, not 0x%x+%lu\n", i, array[i].str,                       array[i].chr, rv, array[i].str, array[i].off);                return PR_FALSE;            }        }    }    printf("PASS\n");    return PR_TRUE;}/* PL_strrchr */PRBool test_016(void){    static struct    {        const char *str;        char        chr;        PRBool      ret;        PRUint32    off;    } array[] =      {          { (const char *)0, 'a', PR_FALSE, 0 },          { (const char *)0, '\0', PR_FALSE, 0 },          { "abcdefg", 'a', PR_TRUE, 0 },          { "abcdefg", 'b', PR_TRUE, 1 },          { "abcdefg", 'c', PR_TRUE, 2 },          { "abcdefg", 'd', PR_TRUE, 3 },          { "abcdefg", 'e', PR_TRUE, 4 },          { "abcdefg", 'f', PR_TRUE, 5 },          { "abcdefg", 'g', PR_TRUE, 6 },          { "abcdefg", 'h', PR_FALSE, 0 },          { "abcdefg", '\0', PR_TRUE, 7 },          { "abcdefg", 'A', PR_FALSE, 0 },          { "abcdefg", 'B', PR_FALSE, 0 },          { "abcdefg", 'C', PR_FALSE, 0 },          { "abcdefg", 'D', PR_FALSE, 0 },          { "abcdefg", 'E', PR_FALSE, 0 },          { "abcdefg", 'F', PR_FALSE, 0 },          { "abcdefg", 'G', PR_FALSE, 0 },          { "abcdefg", 'H', PR_FALSE, 0 },          { "abcdefgabcdefg", 'a', PR_TRUE, 7 },          { "abcdefgabcdefg", 'b', PR_TRUE, 8 },          { "abcdefgabcdefg", 'c', PR_TRUE, 9 },          { "abcdefgabcdefg", 'd', PR_TRUE, 10 },          { "abcdefgabcdefg", 'e', PR_TRUE, 11 },          { "abcdefgabcdefg", 'f', PR_TRUE, 12 },          { "abcdefgabcdefg", 'g', PR_TRUE, 13 },          { "abcdefgabcdefg", 'h', PR_FALSE, 0 },          { "abcdefgabcdefg", '\0', PR_TRUE, 14 }      };    int i;    printf("Test 016 (PL_strrchr)     ..."); fflush(stdout);    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )    {        char *rv = PL_strrchr(array[i].str, array[i].chr);        if( PR_FALSE == array[i].ret )        {            if( (char *)0 != rv )            {                printf("FAIL %d: %s,%c -> %.32s, not zero\n", i, array[i].str,                       array[i].chr, rv);                return PR_FALSE;            }        }        else        {            if( (char *)0 == rv )            {                printf("FAIL %d: %s,%c -> null, not +%lu\n", i, array[i].str,                       array[i].chr, array[i].off);                return PR_FALSE;            }            if( &array[i].str[ array[i].off ] != rv )            {                printf("FAIL %d: %s,%c -> 0x%x, not 0x%x+%lu\n", i, array[i].str,                       array[i].chr, rv, array[i].str, array[i].off);                return PR_FALSE;            }        }    }    printf("PASS\n");    return PR_TRUE;}/* PL_strnchr */PRBool test_017(void){    static struct    {        const char *str;        char        chr;        PRUint32    max;        PRBool      ret;        PRUint32    off;    } array[] =      {          { (const char *)0, 'a', 2, PR_FALSE, 0 },          { (const char *)0, '\0', 2, PR_FALSE, 0 },          { "abcdefg", 'a', 5, PR_TRUE, 0 },          { "abcdefg", 'b', 5, PR_TRUE, 1 },          { "abcdefg", 'c', 5, PR_TRUE, 2 },          { "abcdefg", 'd', 5, PR_TRUE, 3 },          { "abcdefg", 'e', 5, PR_TRUE, 4 },          { "abcdefg", 'f', 5, PR_FALSE, 0 },          { "abcdefg", 'g', 5, PR_FALSE, 0 },          { "abcdefg", 'h', 5, PR_FALSE, 0 },          { "abcdefg", '\0', 5, PR_FALSE, 0 },          { "abcdefg", '\0', 15, PR_TRUE, 7 },          { "abcdefg", 'A', 5, PR_FALSE, 0 },          { "abcdefg", 'B', 5, PR_FALSE, 0 },          { "abcdefg", 'C', 5, PR_FALSE, 0 },          { "abcdefg", 'D', 5, PR_FALSE, 0 },          { "abcdefg", 'E', 5, PR_FALSE, 0 },          { "abcdefg", 'F', 5, PR_FALSE, 0 },          { "abcdefg", 'G', 5, PR_FALSE, 0 },          { "abcdefg", 'H', 5, PR_FALSE, 0 },          { "abcdefgabcdefg", 'a', 10, PR_TRUE, 0 },          { "abcdefgabcdefg", 'b', 10, PR_TRUE, 1 },          { "abcdefgabcdefg", 'c', 10, PR_TRUE, 2 },          { "abcdefgabcdefg", 'd', 10, PR_TRUE, 3 },          { "abcdefgabcdefg", 'e', 10, PR_TRUE, 4 },          { "abcdefgabcdefg", 'f', 10, PR_TRUE, 5 },          { "abcdefgabcdefg", 'g', 10, PR_TRUE, 6 },          { "abcdefgabcdefg", 'h', 10, PR_FALSE, 0 },          { "abcdefgabcdefg", '\0', 10, PR_FALSE, 0 },          { "abcdefgabcdefg", '\0', 14, PR_FALSE, 0 },          { "abcdefgabcdefg", '\0', 15, PR_TRUE, 14 }      };    int i;    printf("Test 017 (PL_strnchr)     ..."); fflush(stdout);    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )    {        char *rv = PL_strnchr(array[i].str, array[i].chr, array[i].max);        if( PR_FALSE == array[i].ret )        {            if( (char *)0 != rv )            {                printf("FAIL %d: %s,%c/%lu -> %.32s, not zero\n", i, array[i].str,                       array[i].chr, array[i].max, rv);                return PR_FALSE;            }        }        else        {            if( (char *)0 == rv )            {                printf("FAIL %d: %s,%c/%lu -> null, not +%lu\n", i, array[i].str,                       array[i].chr, array[i].max, array[i].off);                return PR_FALSE;            }            if( &array[i].str[ array[i].off ] != rv )            {                printf("FAIL %d: %s,%c/%lu -> 0x%x, not 0x%x+%lu\n", i, array[i].str,                       array[i].chr, array[i].max, rv, array[i].str, array[i].off);                return PR_FALSE;            }        }    }    printf("PASS\n");    return PR_TRUE;}/* PL_strnrchr */PRBool test_018(void){    static struct    {        const char *str;        char        chr;        PRUint32    max;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -