Created
October 28, 2009 23:51
-
-
Save tekkub/220990 to your computer and use it in GitHub Desktop.
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
| local function utf8sub(str, start, numChars) | |
| local currentIndex = start | |
| while numChars > 0 and currentIndex <= #str do | |
| local char = string.byte(str, currentIndex) | |
| if char >= 240 then currentIndex = currentIndex + 4 | |
| elseif char >= 225 then currentIndex = currentIndex + 3 | |
| elseif char >= 192 then currentIndex = currentIndex + 2 | |
| else currentIndex = currentIndex + 1 end | |
| numChars = numChars - 1 | |
| end | |
| return str:sub(start, currentIndex - 1) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment