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代码

Minix中的字符判定ctype.c的更多相关文章

  1. c语言中的字符数组与字符串

    1.字符数组的定义与初始化 字符数组的初始化,最容易理解的方式就是逐个字符赋给数组中各元素. char str[10]={ 'I',' ','a','m',' ',‘h’,'a','p','p','y ...

  2. 【C++】C++中的字符和字符串

    目录结构: contents structure [-] 定义和初始化string string对象上的操作 处理string对象中的字符 C风格字符串 标准库类型string表示可变长的字符序列,使 ...

  3. C语言:将s所指字符串中下标为偶数同时ASCII值为奇数的字符删去,-将a所指字符串中的字符和b所指字符串中的字符的顺序交叉,-将形参s所指字符串中的所有数字字符顺序前移,

    //函数fun功能:将s所指字符串中下标为偶数同时ASCII值为奇数的字符删去,s所指串中剩余的字符形成的新串放在t所指的数组中. #include <stdio.h> #include ...

  4. WEB开发中的字符集和编码

    html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...

  5. 解决MVC中JSON字符长度超出限制的异常

    解决MVC中JSON字符长度超出限制的异常 解决方法如下: <configuration> <system.web.extensions> <scripting> ...

  6. div中的字符换行

    div中的字符换行 转载自:http://blog.sina.com.cn/s/blog_6a79bc480100tizi.html   1.强制不换行,同时以省略号结尾. <div style ...

  7. .NET Framework 中的字符编码

    字符是可用多种不同方式表示的抽象实体. 字符编码是一种为受支持字符集中的每个字符进行配对的系统,配对时使用的是表示该字符的某些值. 例如,摩尔斯电码是一种为罗马字母表中的每个字符进行配对的字符编码,配 ...

  8. 在SQL中取出字符串中数字部分或在SQL中取出字符部分

    在SQL中取出字符串中数字部分或在SQL中取出字符部分 编写人:CC阿爸 2013-10-18 近来在开发一个项目时,一包含数字的字符串,需要取出中间的数字部分进行排序.经过baidu搜索.并结合自己 ...

  9. [转]bat中的特殊字符,以及需要在bat中当做字符如何处理

    bat中的特殊字符,以及需要在bat中当做字符如何处理 批处理.Bat 中特殊符号的实际作用,Windows 批处理中特殊符号的作用: @ \\隐藏命令的回显. ~ \\在for中表示使用增强的变量扩 ...

随机推荐

  1. categorys源码

    CREATE TABLE `category` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `editdate` char(20) NOT NUL ...

  2. 【WP8】同步执行异步代码

    微软的StorageFile只支持异步的方式进行文件操作,我之前也封装过一个StorageHelper,但是当所有的方法都是异步的时候也带来一些问题 1.比如我们不能在构造函数调用异步代码(等待), ...

  3. jmeter正则表达式提取器--关联

    http://desert3.iteye.com/blog/1394934 1.http://www.cnblogs.com/quange/archive/2010/06/11/1756260.htm ...

  4. 【Jupyter notebook】access remotly

    http://jupyter-notebook.readthedocs.io/en/latest/public_server.html

  5. json字符串使用注意问题

    json本身是字符串,即 json字符串 js使用 要把 json字符串 转为  javascript对象 json字符串转为js对象的方法:jquery的parseJSON var str='[{& ...

  6. notepad++ 文本替换功能,解决excel批量修改数据库的数据操作

    ^ \(' 开始\t ',' 制表符$ '\) 行末 复制出来之后,使用文本替换功能,转换为SQL,添加到临时表中.然后多表关联修改. SELECT COUNT(*) FROM orderno; # ...

  7. mysql中date_add()函数的使用?

    需求描述: 在使用mysql的过程中,需要对日期进行计算,比如对某个日期加上几天,几个小时等操作, 在此记录下,date_add()函数的使用. 操作过程: date_add()函数语法: DATE_ ...

  8. java登录央行征信网站

    package com.entrym.crawler.test; import java.util.HashMap; import java.util.Map; import org.apache.c ...

  9. 一些JavaScript基本函数

    1.document.write(”");为 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:document->html->(head,body) 4.一个浏览 ...

  10. 删除ORACLE目录OCI.dll文件无法删除 (转)

    删除ORACLE目录OCI.dll文件无法删除 今天准备把虚拟机里的10g卸载安装11g来研究一些新特性 卸载没有用自带的UnInstall工具之前看warehouse的讲课视频凭记忆手动卸载了下删除 ...