Lua 中文支持 GB23112 完整版

Lua 5.3.5

GB2312 编码表

Lua 字符识别

总共需要修改3个文件

lctype.c一大串数组定义改为

0x00,  /* EOZ */
0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,	/* 0. */
0x00,  0x08,  0x08,  0x08,  0x08,  0x08,  0x00,  0x00,
0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,	/* 1. */
0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
0x0c,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,	/* 2. */
0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,
0x16,  0x16,  0x16,  0x16,  0x16,  0x16,  0x16,  0x16,	/* 3. */
0x16,  0x16,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,
0x04,  0x15,  0x15,  0x15,  0x15,  0x15,  0x15,  0x05,	/* 4. */
0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,
0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,	/* 5. */
0x05,  0x05,  0x05,  0x04,  0x04,  0x04,  0x04,  0x05,
0x04,  0x15,  0x15,  0x15,  0x15,  0x15,  0x15,  0x05,	/* 6. */
0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,
0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,	/* 7. */
0x05,  0x05,  0x05,  0x04,  0x04,  0x04,  0x04,  0x00,
0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,	/* 8. */
0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,	/* 9. */
0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
0x00,  0x24,  0x24,  0x24,  0x24,  0x24,  0x24,  0x24,	/* a. */
0x24,  0x24,  0x24,  0x24,  0x24,  0x24,  0x24,  0x24,
0x64,  0x64,  0x64,  0x64,  0x64,  0x64,  0x64,  0x64,	/* b. */
0x64,  0x64,  0x64,  0x64,  0x64,  0x64,  0x64,  0x64,
0x64,  0x64,  0x64,  0x64,  0x64,  0x64,  0x64,  0x64,	/* c. */
0x64,  0x64,  0x64,  0x64,  0x64,  0x64,  0x64,  0x64,
0x64,  0x64,  0x64,  0x64,  0x64,  0x64,  0x64,  0x64,	/* d. */
0x64,  0x64,  0x64,  0x64,  0x64,  0x64,  0x64,  0x64,
0x64,  0x64,  0x64,  0x64,  0x64,  0x64,  0x64,  0x64,	/* e. */
0x64,  0x64,  0x64,  0x64,  0x64,  0x64,  0x64,  0x64,
0x64,  0x64,  0x64,  0x64,  0x64,  0x64,  0x64,  0x64,	/* f. */
0x24,  0x24,  0x24,  0x24,  0x24,  0x24,  0x24,  0x00

lctype.h

#include <limits.h>
#include "llimits.h"

#define ALPHABIT    0
#define DIGITBIT    1
#define PRINTBIT    2
#define SPACEBIT    3
#define XDIGITBIT   4
#define GBLBIT      5   //GB2312低位
#define GBHBIT      6   //GB2312高位

#define MASK(B)		(1 << (B))
#define testprop(c,p)	(luai_ctype_[(c)+1] & (p))
#define lislalpha(c)	testprop(c, (MASK(ALPHABIT)|MASK(GBHBIT)))	            //添加 高位判断
#define lislalnum(c)    testprop(c, (MASK(ALPHABIT)|MASK(DIGITBIT)|MASK(GBHBIT)))   //添加 高位判断
#define lisdigit(c)     testprop(c, MASK(DIGITBIT))
#define lisspace(c)     testprop(c, MASK(SPACEBIT))
#define lisprint(c)     testprop(c, MASK(PRINTBIT))
#define lisxdigit(c)    testprop(c, MASK(XDIGITBIT))
#define lisgbl(c)       testprop(c, MASK(GBLBIT))  //GB2312低位判断
#define lisgbh(c)       testprop(c, MASK(GBHBIT))  //GB2312高位判断
#define ltolower(c)	((c) | ('A' ^ 'a'))
LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2];

llex.c中llex函数的default中的do..while循环改为:

do {
    if(lisgbh(ls->current)) //添加此判断
    {
        save_and_next(ls); 
        if(!lisgbl(ls->current)) break; 
    }
    save_and_next(ls);     
} while (lislalnum(ls->current));

这样Lua就可以支持完整的GB2312中文字符,不会包含特殊符号和繁体字。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值