Minix中的字符判定ctype.c
来源:互联网 发布:mac 如何打破折号 编辑:程序博客网 时间:2024/06/05 03:41
minix中关于如何判定一个字符的类型,如大写、小写、数字……
如果采用传统的方法,如判断一个字母大写的方法:
如果采用传统的方法,如判断一个字母大写的方法:
if(c>='A' && c<'Z') return true;
但是如果判断一个字符是数字或是字母,则采用下面的代码:
if((c<'z' && c>'a') || (c<'Z' && c>'A') || (c>'0' && c<'9')) return true
如果假设更多的局限,效率明显下降
minix的做法是定义一个256元素的unsigned char _ctypes[]数组,由于8位需要8种属性分别描述,如下:
#define _U0x01/* this bit is for upper-case letters [A-Z] */#define _L0x02/* this bit is for lower-case letters [a-z] */#define _N0x04/* this bit is for numbers [0-9] */#define _S0x08/* this bit is for white space \t \n \f etc */#define _P0x10/* this bit is for punctuation characters */#define _C0x20/* this bit is for control characters */#define _X0x40/* this bit is for hex digits [a-f] and [A-F]*/
#define_PROTOTYPE(function, params)function params
判断字符函数原型:
_PROTOTYPE( int isalnum, (int _c) );/* alphanumeric [a-z], [A-Z], [0-9] */_PROTOTYPE( int isalpha, (int _c) );/* alphabetic */_PROTOTYPE( int iscntrl, (int _c) );/* control characters */_PROTOTYPE( int isdigit, (int _c) );/* digit [0-9] */_PROTOTYPE( int isgraph, (int _c) );/* graphic character */_PROTOTYPE( int islower, (int _c) );/* lower-case letter [a-z] */_PROTOTYPE( int isprint, (int _c) );/* printable character */_PROTOTYPE( int ispunct, (int _c) );/* punctuation mark */_PROTOTYPE( int isspace, (int _c) );/* white space sp, \f, \n, \r, \t, \v*/_PROTOTYPE( int isupper, (int _c) );/* upper-case letter [A-Z] */_PROTOTYPE( int isxdigit,(int _c) );/* hex digit [0-9], [a-f], [A-F] */_PROTOTYPE( int tolower, (int _c) );/* convert to lower-case */_PROTOTYPE( int toupper, (int _c) );/* convert to upper-case */
以上函数都是通过宏定义:
#define isalnum(c)((__ctype+1)[c]&(_U|_L|_N))#define isalpha(c)((__ctype+1)[c]&(_U|_L))#define iscntrl(c)((__ctype+1)[c]&_C)#define isgraph(c)((__ctype+1)[c]&(_P|_U|_L|_N))#define ispunct(c)((__ctype+1)[c]&_P)#define isspace(c)((__ctype+1)[c]&_S)#define isxdigit(c)((__ctype+1)[c]&(_N|_X))#define isdigit(c)((unsigned) ((c)-'0') < 10)#define islower(c)((unsigned) ((c)-'a') < 26)#define isupper(c)((unsigned) ((c)-'A') < 26)#define isprint(c)((unsigned) ((c)-' ') < 95)#define isascii(c)((unsigned) (c) < 128)
minix将_ctype[]初始化为:
char __ctype[] = {0,_C,_C,_C,_C,_C,_C,_C,_C,_C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C,_C,_C,_C,_C,_C,_C,_C,_C,_C,_C,_C,_C,_C,_C,_C,_C,_S,_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,_P,_P,_P,_P,_P,_P,_P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_P,_P,_P,_P,_P,_P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_P,_P,_P,_P,_C,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,};
- Minix中的字符判定ctype.c
- c中的ctype.h字符函数
- ctype.h中的关于字符判断
- C/C++中字符函数库ctype.h
- ctype.c
- C语言再学习 -- ctype.h字符判断函数
- C Primer Plus学习 十一 ctype.h系列字符函数
- 7.5 C控制语句:ctype.h系列的字符函数
- C语言ctype.h系列的字符函数
- C和指针之字符操作(<ctype.h>)
- ctype.h和ctype.c在Linux中的实现方式与编码艺术
- ctype字符处理
- 37、C#,判定小数;格式化字符
- Minix源代码中的汇编
- c ctype.h
- ctype.c程序
- c library-ctype.h
- 【C】ctype.h文件
- 在 Windows 上安装和使用 GNUstep 和 Objective-C
- 【分享】PK10彩票历史数据
- Nginx Rewrite重写
- Android系统Recovery工作原理之使用update.zip升级过程分析(四)
- hdu4441 Queue Sequence(线段树+splay)
- Minix中的字符判定ctype.c
- Extjs中隐藏某个textfield以及label组件的方法
- 这辈子让我讨厌到无以复加的两个人的对话
- input 按钮背景,在IE6 IE7中不显示
- 【xtku】笔者支招:Win 8针对开始屏幕与开始菜单的比较
- Codeforces 2B The least round way 动态规划
- 交换机的几种配置方法
- 这是一个为了学习C语言而开通的博客
- Android工程下assets文件夹与res文件夹的区别