2.8.4. _get_lc_ctype()

链接时选择的 CTYPE 实现为以下内容之一:

您可以定义自己的 CTYPE 属性表,该表具有以下特征:

数组中的第一个元素(位于 -1 处)必须是 0。 Example 2.10 说明了返回 CTYPE 数据的函数的框架实现。 还说明了一些用于定义多字节 LC_CTYPE 区域设置的宏,例如,LC_MBCTYPE_DEF。 有关详细信息,请参阅 rt_locale.h 文件。

Example 2.10. LC_CTYPE_DEF 表


__LC_CTYPE_DEF(lcctype_c, "C")

{

    __C, __C, __C, __C, __C, __C, __C, __C, __C,            /* 0x00-0x08 */	

    __C+__S,__C+__S,__C+__S,__C+__S,__C+__S,    /* 0x09-0x0D (BS,LF,VT,FF,CR) */	

    __C, __C, __C, __C, __C, __C, __C, __C, __C,            /* 0x0E-0x16 */	

    __C, __C, __C, __C, __C, __C, __C, __C, __C,            /* 0x17-0x1F */	

    __B+__S,                                                /* space */	

    __P, __P, __P, __P, __P, __P, __P, __P,                 /* !"#$%&'( */	

    __P, __P, __P, __P, __P, __P, __P,                      /* )*+,-./ */	

    __N, __N, __N, __N, __N, __N, __N, __N, __N, __N,       /* 0-9 */	

    __P, __P, __P, __P, __P, __P, __P,                      /* :;<=>?@ */	

    __U+__X, __U+__X, __U+__X, __U+__X, __U+__X, __U+__X,   /* A-F */	

    __U, __U, __U, __U, __U, __U, __U, __U, __U, __U,       /* G-P */	

    __U, __U, __U, __U, __U, __U, __U, __U, __U, __U,       /* Q-Z */	

    __P, __P, __P, __P, __P, __P,                           /* [\]^_` */	

    __L+__X, __L+__X, __L+__X, __L+__X, __L+__X, __L+__X,   /* a-f */	

    __L, __L, __L, __L, __L, __L, __L, __L, __L, __L,       /* g-p */	

    __L, __L, __L, __L, __L, __L, __L, __L, __L, __L,       /* q-z */	

    __P, __P, __P, __P,                                     /* {|}~ */	

    __C,                                                    /* 0x7F */	

    /* the whole of the top half is illegal characters */	

    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

};

__LC_CTYPE_DEF(lcctype_iso8859_1, "ISO8859-1")

{

    __C, __C, __C, __C, __C, __C, __C, __C, __C,            /* 0x00-0x08 */	

    __C+__S,__C+__S,__C+__S,__C+__S,__C+__S,  /* 0x09-0x0D (BS,LF,VT,FF,CR) */	

    __C, __C, __C, __C, __C, __C, __C, __C, __C,            /* 0x0E-0x16 */	

    __C, __C, __C, __C, __C, __C, __C, __C, __C,            /* 0x17-0x1F */	

    __B+__S,                                                /* space */	

    __P, __P, __P, __P, __P, __P, __P, __P,                 /* !"#$%&'( */	

    __P, __P, __P, __P, __P, __P, __P,                      /* )*+,-./ */	

    __N, __N, __N, __N, __N, __N, __N, __N, __N, __N,       /* 0-9 */	

    __P, __P, __P, __P, __P, __P, __P,                      /* :;<=>?@ */	

    __U+__X, __U+__X, __U+__X, __U+__X, __U+__X, __U+__X,   /* A-F */	

    __U, __U, __U, __U, __U, __U, __U, __U, __U, __U,       /* G-P */	

    __U, __U, __U, __U, __U, __U, __U, __U, __U, __U,       /* Q-Z */	

    __P, __P, __P, __P, __P, __P,                           /* [\]^_` */ 	

    __L+__X, __L+__X, __L+__X, __L+__X, __L+__X, __L+__X,   /* a-f */	

    __L, __L, __L, __L, __L, __L, __L, __L, __L, __L,       /* g-p */	

    __L, __L, __L, __L, __L, __L, __L, __L, __L, __L,       /* q-z */	

    __P, __P, __P, __P,                                     /* {|}~ */	

    __C,                                                    /* 0x7F */	

    /* ISO8859-1 top half:	

     * - 0x80-0x9f are control chars	

     * - 0xa0 is nonbreaking space (whitespace)	

     * - 0xa1-0xbf are punctuation chars	

     * - 0xc0-0xdf are uppercase chars except times sign at 0xd7  	

     * - 0xe0-0xff are lowercase chars except divide sign at 0xf7 */	

    __C,__C,__C,__C,__C,__C,__C,__C,       /* 0x80 - 0x87 */	

    __C,__C,__C,__C,__C,__C,__C,__C,       /* 0x88 - 0x8f */	

    __C,__C,__C,__C,__C,__C,__C,__C,       /* 0x90 - 0x97 */	

    __C,__C,__C,__C,__C,__C,__C,__C,       /* 0x98 - 0x9f */	

    __B+__S,__P,__P,__P,__P,__P,__P,__P,   /* 0xa0 - 0xa7 */	

    __P,__P,__P,__P,__P,__P,__P,__P,       /* 0xa8 - 0xaf */	

    __P,__P,__P,__P,__P,__P,__P,__P,       /* 0xb0 - 0xb7 */	

    __P,__P,__P,__P,__P,__P,__P,__P,       /* 0xb8 - 0xbf */	

    __U,__U,__U,__U,__U,__U,__U,__U,       /* 0xc0 - 0xc7 */	

    __U,__U,__U,__U,__U,__U,__U,__U,       /* 0xc8 - 0xcf */	

    __U,__U,__U,__U,__U,__U,__U,__P,       /* 0xd0 - 0xd7 */	

    __U,__U,__U,__U,__U,__U,__U,__U,       /* 0xd8 - 0xdf */	

    __L,__L,__L,__L,__L,__L,__L,__L,       /* 0xe0 - 0xe7 */	

    __L,__L,__L,__L,__L,__L,__L,__L,       /* 0xe8 - 0xef */	

    __L,__L,__L,__L,__L,__L,__L,__P,       /* 0xf0 - 0xf7 */	

    __L,__L,__L,__L,__L,__L,__L,__L,       /* 0xf8 - 0xff */	

};

_LC_INDEX_END(lcctype_dummy)



void const *_get_lc_ctype(void const *null, char const *name) {	

    return _findlocale(&lcctype_c_index, name);	

}



void test_lc_ctype(void) {

    EQS(setlocale(LC_CTYPE, NULL), "C");  /* verify starting point */	

    EQI(!!isalpha('@'), 0);               /* test off-by-one */	

    EQI(!!isalpha('A'), 1);	

    EQI(!!isalpha('\xc1'), 0);            /* C locale: isalpha(Aacute)==0 */	

    EQI(!setlocale(LC_CTYPE, "ISO8859-1"), 0);

    EQS(setlocale(LC_CTYPE, NULL), "ISO8859-1");	

    EQI(!!isalpha('@'), 0);               /* test off-by-one */	

    EQI(!!isalpha('A'), 1);	

    EQI(!!isalpha('\xc1'), 1);            /* ISO8859 locale: isalpha(Aacute)!=0 */	

    EQI(!setlocale(LC_CTYPE, "C"), 0);

    EQS(setlocale(LC_CTYPE, NULL), "C");	

    EQI(!!isalpha('@'), 0);               /* test off-by-one */	

    EQI(!!isalpha('A'), 1);	

    EQI(!!isalpha('\xc1'), 0);            /* C locale: isalpha(Aacute)==0 */	

}

Copyright © 2007 ARM Limited. All rights reserved. ARM DUI 0349AC
Non-Confidential