Skip to content

Commit

Permalink
Implemented utf8.charpattern for #319
Browse files Browse the repository at this point in the history
  • Loading branch information
hymkor committed Jun 10, 2018
1 parent 3a6125a commit 7b53603
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions mains/utf8lua.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ func utf8codes(L *lua.LState) int {
func SetupUtf8Table(L *lua.LState) {
table := L.NewTable()
L.SetField(table, "codes", L.NewFunction(utf8codes))
L.SetField(table, "charpattern", lua.LString("[\000-\x7F\xC2-\xF4][\x80-\xBF]*"))
L.SetGlobal("utf8", table)
}
9 changes: 9 additions & 0 deletions t/tst_utf8lib.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@

--- Compare
--- lua_f tst_utf8lib.lua
-- and
--- lua.exe tst_utf8lib.lua | nkf32

for i,c in utf8.codes("あいうえお") do
print(i,c,type(c))
end

for c in string.gmatch("あいうえお",utf8.charpattern) do
print(c)
end

0 comments on commit 7b53603

Please sign in to comment.