Created
May 27, 2016 11:27
-
-
Save mutoo/d89d3d4105ad232c805301a6714954f0 to your computer and use it in GitHub Desktop.
check given utf8 character was Chinese or not.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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