- 论坛徽章:
- 0
|
上一层还没弄清楚就进入细节,当然会越来越糊涂。而且不知道你看的是哪个版本。- enum
- {
- _ISupper = _ISbit (0), /* UPPERCASE. */
- _ISlower = _ISbit (1), /* lowercase. */
- _ISalpha = _ISbit (2), /* Alphabetic. */
- _ISdigit = _ISbit (3), /* Numeric. */
- _ISxdigit = _ISbit (4), /* Hexadecimal numeric. */
- _ISspace = _ISbit (5), /* Whitespace. */
- _ISprint = _ISbit (6), /* Printing. */
- _ISgraph = _ISbit (7), /* Graphical. */
- _ISblank = _ISbit (8), /* Blank (usually SPC and TAB). */
- _IScntrl = _ISbit (9), /* Control character. */
- _ISpunct = _ISbit (10), /* Punctuation. */
- _ISalnum = _ISbit (11) /* Alphanumeric. */
- };
- #endif /* ! _ISbit */
- /* These are defined in ctype-info.c.
- The declarations here must match those in localeinfo.h.
- In the thread-specific locale model (see `uselocale' in <locale.h>)
- we cannot use global variables for these as was done in the past.
- Instead, the following accessor functions return the address of
- each variable, which is local to the current thread if multithreaded.
- These point into arrays of 384, so they can be indexed by any `unsigned
- char' value [0,255]; by EOF (-1); or by any `signed char' value
- [-128,-1). ISO C requires that the ctype functions work for `unsigned
- char' values and for EOF; we also support negative `signed char' values
- for broken old programs. The case conversion arrays are of `int's
- rather than `unsigned char's because tolower (EOF) must be EOF, which
- doesn't fit into an `unsigned char'. But today more important is that
- the arrays are also used for multi-byte character sets. */
- extern __const unsigned short int **__ctype_b_loc (void)
- __attribute__ ((__const));
- extern __const __int32_t **__ctype_tolower_loc (void)
- __attribute__ ((__const));
- extern __const __int32_t **__ctype_toupper_loc (void)
- __attribute__ ((__const));
- #define __isctype(c, type) \
- ((*__ctype_b_loc ())[(int) (c)] & (unsigned short int) type)
复制代码 __isctype 是用来判断一个字符是否属于某一类,类别是在enum里面确定好的,每类对应一个bit。方法就是在一个数组中检索这个字符的类型,然后与type做AND,检测对应的bit是否设置。
__ctype_b_loc在上面的注释里面也一清二楚,为了支持多线程云云,...,他返回了一个384个字节的数组(128+256=384),指针指向第128个字节的位置,这样的话,就算你传递一个负的signed char [-128, -1],也不会出错。 |
|