X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=internal%2Futil%2Flua.go;h=eda14981f1c31b344953a26ea702fa061b40d87c;hb=965e43ebf1319947a325f252000985fb0a586449;hp=3f0393d410e861dd2feb6b2b6e1006dfe6b608fa;hpb=e3ae38e54a71d7cb3ae663ac9ca9339c981b6dff;p=micro.git diff --git a/internal/util/lua.go b/internal/util/lua.go index 3f0393d4..eda14981 100644 --- a/internal/util/lua.go +++ b/internal/util/lua.go @@ -1,13 +1,11 @@ package util -import ( - "unicode/utf8" -) - +// LuaRuneAt is a helper function for lua plugins to return the rune +// at an index within a string func LuaRuneAt(str string, runeidx int) string { i := 0 for len(str) > 0 { - r, size := utf8.DecodeRuneInString(str) + r, _, size := DecodeCharacterInString(str) str = str[size:] @@ -20,10 +18,11 @@ func LuaRuneAt(str string, runeidx int) string { return "" } +// LuaGetLeadingWhitespace returns the leading whitespace of a string (used by lua plugins) func LuaGetLeadingWhitespace(s string) string { ws := []byte{} for len(s) > 0 { - r, size := utf8.DecodeRuneInString(s) + r, _, size := DecodeCharacterInString(s) if r == ' ' || r == '\t' { ws = append(ws, byte(r)) } else { @@ -35,7 +34,8 @@ func LuaGetLeadingWhitespace(s string) string { return string(ws) } +// LuaIsWordChar returns true if the first rune in a string is a word character func LuaIsWordChar(s string) bool { - r, _ := utf8.DecodeRuneInString(s) + r, _, _ := DecodeCharacterInString(s) return IsWordChar(r) }