Skip to content

Instantly share code, notes, and snippets.

@mutoo
Created May 27, 2016 11:27
Show Gist options
  • Select an option

  • Save mutoo/d89d3d4105ad232c805301a6714954f0 to your computer and use it in GitHub Desktop.

Select an option

Save mutoo/d89d3d4105ad232c805301a6714954f0 to your computer and use it in GitHub Desktop.
check given utf8 character was Chinese or not.
function isChinese(s, ci)
local lower = { 228, 184, 128 } -- 0x4E00
local middl = { 224, 128, 128 }
local upper = { 233, 190, 165 } -- 0x9FA5
for i, v in ipairs(lower) do
local c = s[ci + i - 1]
if c < v then
return false
elseif c > v then
break
end
end
for i, v in ipairs(upper) do
local c = s[ci + i - 1]
if c > v then
return false
elseif c < middl[i] then
return false
elseif c < v then
break
end
end
return true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment