---计算字符是否为中文
---@param inputstr string
function StringUtil.isChineseCharacter(inputstr)
-- 可以计算出字符宽度,用于显示使用
local isChineseCharacter = true
local lenInByte = #inputstr
local i = 1
while (i <= lenInByte)
do
local curByte = string.byte(inputstr, i)
-- Logger.filter("StringUtil",i, lenInByte, curByte)
local byteCount = 1;
-- print("isChineseCharacter", i, curByte)
if curByte > 0 and curByte <= 127 then
isChineseCharacter = false
byteCount = 1 --1字节字符
break
elseif curByte >= 192 and curByte <= 223 then
byteCount = 2 --双字节字符
elseif curByte >= 228 and curByte <= 233 then
byteCount = 3 --汉字
elseif curByte >= 240 and curByte <= 247 then
byteCount = 4 --4字节字符
else
isChineseCharacter = false
break
end
i = i + byteCount -- 重置下一字节的索引
end
return isChineseCharacter
end