minix中关于如何判定一个字符的类型,如大写、小写、数字……
如果采用传统的方法,如判断一个字母大写的方法:

if(c>='A' && c<'Z')  return true;

但是如果判断一个字符是数字或是字母,则采用下面的代码:

if((c<'z' && c>'a') || (c<'Z' && c>'A') || (c>'' && c<''))  return true

如果假设更多的局限,效率明显下降
minix的做法是定义一个256元素的unsigned char _ctypes[]数组,由于8位需要8种属性分别描述,如下:

#define _U        0x01    /* this bit is for upper-case letters [A-Z] */
#define _L 0x02 /* this bit is for lower-case letters [a-z] */
#define _N 0x04 /* this bit is for numbers [0-9] */
#define _S 0x08 /* this bit is for white space \t \n \f etc */
#define _P 0x10 /* this bit is for punctuation characters */
#define _C 0x20 /* this bit is for control characters */
#define _X 0x40 /* 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[] = {
,
_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,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
};

C代码

最新文章

  1. 手把手教你用FineBI做数据可视化
  2. C# WinForm 中英文实现, 国际化实现的简单方法
  3. Intellij jrebel 热部署
  4. Java for LeetCode 230 Kth Smallest Element in a BST
  5. linux进程的堆栈空间_代码段(指令,只读)、数据段(静态变量,全局变量)、堆栈段(局部变量)、栈【转】
  6. [C/C++]C++声明
  7. [CSS] Introduction to CSS Columns
  8. cent0s7 显卡驱动导致重启黑屏
  9. JavaEE中遗漏的10个最重要的安全控制
  10. react-redux原理
  11. schema文件中cube的事实表使用视图方法
  12. Libev学习笔记1
  13. intellij IDEA mybatis插件破解方法
  14. Tensorboard可视化(关于TensorFlow不同版本引起的错误)
  15. Base64字符 转图片乱码问题
  16. 求n!中含有某个因子个数的方法
  17. GraphHttpClient概述
  18. HDU ACM 1879 继续畅通工程
  19. Docker相关
  20. Package has no installation candidate解决方法

热门文章

  1. hql date比较
  2. 条理清晰的搭建SSH环境之整合Struts和Spring
  3. Android 混淆代码有关问题总结
  4. 配置nginx.config 报错:connect() failed (111: Connection refused) while connecting to upstream解决
  5. HTML5标签canvas制作动画
  6. Eclipse------启动Server时出现弹窗Server at localhost was unable to start within 45 seconds.
  7. SPREAD for Windows Forms 代码片段
  8. 【剑指Offer学习】【面试题23:从上往下打印二叉树】
  9. SpringMVC -- 梗概--源码--壹--收参
  10. c# new的三种用法