与 Lua 模式匹配的精确 Ascii 代码
Exact Ascii codes matched by Lua patterns
我正在将一个项目从 Lua 翻译成 C++。在 Lua 版本中,我使用 Lua 的正则表达式,但出于如此简单的目的,在 C++ 中我可以通过简单地将字符与一些 Ascii 代码进行比较来完成。
但是,要做到这一点,我需要每个 character class 匹配的确切 ascii 码。
例如,%s
匹配所有 space 个字符,但这些字符到底是什么?我需要知道每个 Lua 个字符 class.
看看 Lua source:
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 值范围。
我正在将一个项目从 Lua 翻译成 C++。在 Lua 版本中,我使用 Lua 的正则表达式,但出于如此简单的目的,在 C++ 中我可以通过简单地将字符与一些 Ascii 代码进行比较来完成。
但是,要做到这一点,我需要每个 character class 匹配的确切 ascii 码。
例如,%s
匹配所有 space 个字符,但这些字符到底是什么?我需要知道每个 Lua 个字符 class.
看看 Lua source:
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 值范围。