zoukankan      html  css  js  c++  java
  • 无视编码都统一转成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..''

    -- 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

  • 相关阅读:
    JDBC 复习4 批量执行SQL
    JDBC 复习3 存取Oracle大数据 clob blob
    Oracle复习
    Linux命令(1)grep
    JDBC 复习2 存取mysql 大数据
    JDBC 复习1 DBUtil
    php 环境搭建问题
    Windows 批处理 bat 开启 WiFi 菜单选项 设置ID PWD
    Bat 批处理启动和停止Oracle 服务
    docker 学习1 WSL docker ,Windows docker
  • 原文地址:https://www.cnblogs.com/rexzhao/p/6553499.html
Copyright © 2011-2022 走看看