无视编码都统一转成unicode 然后截断 例如 。“发发发发发发” 操作之后显示为 “发发发发...”
-- local function checkPlayName( str )
-- str = Utils.utf8_to_unicode(str)
-- local retStr = ""
-- local num = 0
-- local lenInByte = #str
-- local x = 1
-- for i=1,lenInByte do
-- i = x
-- local curByte = string.byte(str, x)
-- local byteCount = 1;
-- if curByte>0 and curByte<=127 then
-- byteCount = 1
-- elseif curByte>127 and curByte<240 then
-- byteCount = 3
-- elseif curByte>=240 and curByte<=247 then
-- byteCount = 4
-- end
-- local curStr = string.sub(str, i, i+byteCount-1)
-- retStr = retStr .. curStr
-- x = x + byteCount
-- if x >= lenInByte then
-- local finalRetStr = Utils.unicode_to_utf8(retStr)
-- return finalRetStr
-- end
-- num = num + 1
-- if num >= 24 then
-- retStr = retStr.."..."
-- local finalRetStr = Utils.unicode_to_utf8(retStr)
-- return finalRetStr
-- end
-- end
-- local finalRetStr = Utils.unicode_to_utf8(retStr)
-- return finalRetStr
-- end
-- Utils.checkPlayName = checkPlayName
-- local bit = require("bit")
-- local function unicode_to_utf8(convertStr)
-- if type(convertStr)~="string" then
-- return convertStr
-- end
-- local resultStr=""
-- local i=1
-- while true do
-- local num1=string.byte(convertStr,i)
-- local unicode
-- if num1~=nil and string.sub(convertStr,i,i+1)=="\\u" then
-- unicode=tonumber("0x"..string.sub(convertStr,i+2,i+5))
-- i=i+6
-- elseif num1~=nil then
-- unicode=num1
-- i=i+1
-- else
-- break
-- end
-- print(unicode)
-- if unicode <= 0x007f then
-- resultStr=resultStr..string.char(bit.band(unicode,0x7f))
-- elseif unicode >= 0x0080 and unicode <= 0x07ff then
-- resultStr=resultStr..string.char(bit.bor(0xc0,bit.band(bit.rshift(unicode,6),0x1f)))
-- resultStr=resultStr..string.char(bit.bor(0x80,bit.band(unicode,0x3f)))
-- elseif unicode >= 0x0800 and unicode <= 0xffff then
-- resultStr=resultStr..string.char(bit.bor(0xe0,bit.band(bit.rshift(unicode,12),0x0f)))
-- resultStr=resultStr..string.char(bit.bor(0x80,bit.band(bit.rshift(unicode,6),0x3f)))
-- resultStr=resultStr..string.char(bit.bor(0x80,bit.band(unicode,0x3f)))
-- end
-- end
-- resultStr=resultStr..'\0'
-- print(resultStr)
-- return resultStr
-- end
-- Utils.unicode_to_utf8 = unicode_to_utf8
-- local function utf8_to_unicode(convertStr)
-- if type(convertStr)~="string" then
-- return convertStr
-- end
-- local resultStr=""
-- local i=1
-- local num1=string.byte(convertStr,i)
-- while num1~=nil do
-- print(num1)
-- local tempVar1,tempVar2
-- if num1 >= 0x00 and num1 <= 0x7f then
-- tempVar1=num1
-- tempVar2=0
-- elseif bit.band(num1,0xe0)== 0xc0 then
-- local t1 = 0
-- local t2 = 0
-- t1 = bit.band(num1,bit.rshift(0xff,3))
-- i=i+1
-- num1=string.byte(convertStr,i)
-- t2 = bit.band(num1,bit.rshift(0xff,2))
-- tempVar1=bit.bor(t2,bit.lshift(bit.band(t1,bit.rshift(0xff,6)),6))
-- tempVar2=bit.rshift(t1,2)
-- elseif bit.band(num1,0xf0)== 0xe0 then
-- local t1 = 0
-- local t2 = 0
-- local t3 = 0
-- t1 = bit.band(num1,bit.rshift(0xff,3))
-- i=i+1
-- num1=string.byte(convertStr,i)
-- t2 = bit.band(num1,bit.rshift(0xff,2))
-- i=i+1
-- num1=string.byte(convertStr,i)
-- t3 = bit.band(num1,bit.rshift(0xff,2))
-- tempVar1=bit.bor(bit.lshift(bit.band(t2,bit.rshift(0xff,6)),6),t3)
-- tempVar2=bit.bor(bit.lshift(t1,4),bit.rshift(t2,2))
-- end
-- resultStr=resultStr..string.format("\\u%02x%02x",tempVar2,tempVar1)
-- print(resultStr)
-- i=i+1
-- num1=string.byte(convertStr,i)
-- end
-- print(resultStr)
-- return resultStr
-- end
-- Utils.utf8_to_unicode = utf8_to_unicode
无视编码都统一转成unicode 然后截断 例如 。“发发发发发发” 操作之后显示为 “发发发发...”的更多相关文章
- 不同格式的ip 统一转成ip列表
支持以下格式的ip地址: 192.168.1.0/24 192.168.1.1-23 192.168.1.123 代码如下: package finder; import java.net.InetA ...
- 编码GBK和GB2312、Unicode、UTF-8
一.编码GBK和GB2312 随着计算机发展,各国已经不满足于单纯用ASCII码: 对于我们来说能在计算机中显示中文字符是至关重要的,所以我们还需要一张关于中文和数字对应的关系表: 一个字节8位二进制 ...
- 控制台程序的中文输出乱码问题(export LC_CTYPE=zh_CN.GBK,或者修改/etc/sysconfig/i18n为zh_CN.GBK。使用setlocale(LC_CTYPE, "");会使用默认办法。编译器会将源码做转换成Unicode格式,或者指定gcc的输入文件的编码参数-finput-charset=GBK。Linux下应该用wprintf(L"%ls/n",wstr))
今天发现用securecrt登陆时,gcc编译出错时会出现乱码,但直接在主机的窗口界面下用Shell编译却没有乱码.查看了一下当时的错误描述,发现它的引号是中文引号,导致在SecureCRT中显示出错 ...
- 字符编码笔记:ASCII,Unicode和UTF-8
很久很久以前,有一群人,他们决定用8个可以开合的晶体管来组合成不同的状态,以表示世界上的万物.他们看到8个开关状态是好的,于是他们把这称为"字节". 再后来,他们又做了一些可以处理 ...
- 字符编码笔记:ASCII,Unicode和UTF-8 转
本文出处 http://www.ruanyifeng.com/blog/2007/10/ascii_unicode_and_utf-8.html 只是为了记录一下省得要去搜. 今天中午,我突然想搞清楚 ...
- [转]字符编码笔记:ASCII,Unicode和UTF-8
转自:http://www.ruanyifeng.com/blog/2007/10/ascii_unicode_and_utf-8.html 作者: 阮一峰 日期: 2007年10月28日 今天中午, ...
- 字符编码笔记:ASCII,Unicode和UTF-8(转载)
作者: 阮一峰 日期: 2007年10月28日 今天中午,我突然想搞清楚Unicode和UTF-8之间的关系,于是就开始在网上查资料. 结果,这个问题比我想象的复杂,从午饭后一直看到晚上9点,才算初步 ...
- UTF-8编码的字符串拆分成单字、获取UTF-8字符串的字符个数的代码及原理
一.字符编码简介 1. ASCII码 在计算机内部,所有的信息最终都表示为一个二进制的字符串.每一个二进制位(bit)有0和1两种状态,因此八个二进制位就可以组合出256种状态,这被称为一个字节(by ...
- 字符编码笔记:ASCII,Unicode和UTF-8【转载】
作者: 阮一峰 日期: 2007年10月28日 今天中午,我突然想搞清楚Unicode和UTF-8之间的关系,于是就开始在网上查资料. 结果,这个问题比我想象的复杂,从午饭后一直看到晚上9点,才算初步 ...
随机推荐
- POJ 3320 Jessica's Reading Problem (尺取法)
Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam is co ...
- PLSQL 问题小记
问题1:在一个拼写长字符串的函数中,若出现ora-06502或者ora-06512的错误,则有可能是在拼串的过程中,数据类型的隐式转换出了问题,如:字符类型转为数字,此时会出现错误. 解决方案:在拼串 ...
- Step2:SQL Server 复制事务发布
一.背景 在复制的运用场景中,事务发布是使用最为广泛的,我遇到这样一个场景:在Task数据库中有Basic与Group两个表,需要提供这两个表的部分字段给其它程序读取放入缓存,程序需要比较及时的获取到 ...
- Kattis之旅——Rational Arithmetic
Input The first line of input contains one integer, giving the number of operations to perform. Then ...
- pxc 集群节点被kill -9 了拿什么拯救?
集群关机或者异常宕机,重启后想要以IST的方式加入集群,需要考虑集群中是否存在满足的节点,该节点的gcache还存放着停机期间所产生的事物. 重新初始化节点加入集群应该是最后的救命稻草. 这里模拟某个 ...
- ora-12705解决方法
最近使用instant sqlplus测试时,遇到ora-12705,一开始以为是少了配置,经查是,NLS_LANG设置问题,设置为"SIMPLIFIED CHINESE_CHINA.ZHS ...
- 锁(lock)和闩(latch)
开发多用户.数据库驱动的应用时,最大的难点之一是:一方面要力争取得最大限度的并发访问,与此同时还要确保每个用户能以一致的方式读取和修改数据.为此就有了锁定(locking)机制,这也是所有数据库都具有 ...
- 无旋转Treap简介
无旋转Treap是一个神奇的数据结构,能够支持插入,删除,查询k大,查询某个数的排名,查询前驱后继,支持各种区间操作和持久化.基于旋转的Treap无法实现区间反转等操作,但是无旋Treap可以轻易地支 ...
- Git 安装和使用教程(转载)
转载:https://www.cnblogs.com/smuxiaolei/p/7484678.html 转载:https://blog.csdn.net/wk_1214BoKe/article/de ...
- PyCharm笔记之配色方案和取消波浪线
转载:http://blog.csdn.net/xiemanr/article/details/72583718 转载:http://www.jb51.net/article/50689.htm 一. ...