这是一个独立于字符集编码的实现,但它只支持只有小写字母是 26 个小写拉丁字母的语言环境(包括默认的 C 语言环境)。
在此处的答案中,它比其他实现占用更多的数据空间,因为它需要一个表,但它应该非常快,只需要几条指令即可对其参数进行零扩展,加载表的地址并查找结果。
#include <limits.h>
int is_lower_101(char a)
{
static char t[UCHAR_MAX+1] = {
[(unsigned char) 'a'] = 1,
[(unsigned char) 'b'] = 1,
[(unsigned char) 'c'] = 1,
[(unsigned char) 'd'] = 1,
[(unsigned char) 'e'] = 1,
[(unsigned char) 'f'] = 1,
[(unsigned char) 'g'] = 1,
[(unsigned char) 'h'] = 1,
[(unsigned char) 'i'] = 1,
[(unsigned char) 'j'] = 1,
[(unsigned char) 'k'] = 1,
[(unsigned char) 'l'] = 1,
[(unsigned char) 'm'] = 1,
[(unsigned char) 'n'] = 1,
[(unsigned char) 'o'] = 1,
[(unsigned char) 'p'] = 1,
[(unsigned char) 'q'] = 1,
[(unsigned char) 'r'] = 1,
[(unsigned char) 's'] = 1,
[(unsigned char) 't'] = 1,
[(unsigned char) 'u'] = 1,
[(unsigned char) 'v'] = 1,
[(unsigned char) 'w'] = 1,
[(unsigned char) 'x'] = 1,
[(unsigned char) 'y'] = 1,
[(unsigned char) 'z'] = 1,
};
return t[(unsigned char) a];
}