与Lua模式匹配的精确Ascii码



我正在把一个项目从Lua翻译成c++。在Lua版本中,我使用了Lua的正则表达式,但目的非常简单,在c++中,我可以通过简单地将字符与一些Ascii码进行比较来实现。

但是,要做到这一点,我需要每个字符类匹配的精确ascii码。

作为一个例子,%s匹配所有的空格字符,但是这些字符到底是什么呢?我需要知道每一个Lua字符类

看一下Lua源码:

case 'a' : res = isalpha(c); break;
case 'c' : res = iscntrl(c); break;
case 'd' : res = isdigit(c); break;
case 'g' : res = isgraph(c); break;
case 'l' : res = islower(c); break;
case 'p' : res = ispunct(c); break;
case 's' : res = isspace(c); break;
case 'u' : res = isupper(c); break;
case 'w' : res = isalnum(c); break;
case 'x' : res = isxdigit(c); break;
case 'z' : res = (c == 0); break;  /* deprecated option */

您可以看到c++ <cctype> (ctype.h)中有类似的方法:

isalnum     Check if character is alphanumeric (function )
isalpha     Check if character is alphabetic (function )
isblank     Check if character is blank (function )
iscntrl     Check if character is a control character (function )
isdigit     Check if character is decimal digit (function )
isgraph     Check if character has graphical representation (function )
islower     Check if character is lowercase letter (function )
isprint     Check if character is printable (function )
ispunct     Check if character is a punctuation character (function )
isspace     Check if character is a white-space (function )
isupper     Check if character is uppercase letter (function )
isxdigit    Check if character is hexadecimal digit (function )

该页上也有相应的ASCII值范围

最新更新