mutoo
5/27/2016 - 11:27 AM

check given utf8 character was Chinese or not.

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