mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-29 22:27:13 +09:00
Autoclose plugin support
This commit is contained in:
41
internal/util/lua.go
Normal file
41
internal/util/lua.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
func LuaRuneAt(str string, runeidx int) string {
|
||||
i := 0
|
||||
for len(str) > 0 {
|
||||
r, size := utf8.DecodeRuneInString(str)
|
||||
|
||||
str = str[size:]
|
||||
|
||||
if i == runeidx {
|
||||
return string(r)
|
||||
}
|
||||
|
||||
i++
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func LuaGetLeadingWhitespace(s string) string {
|
||||
ws := []byte{}
|
||||
for len(s) > 0 {
|
||||
r, size := utf8.DecodeRuneInString(s)
|
||||
if r == ' ' || r == '\t' {
|
||||
ws = append(ws, byte(r))
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
s = s[size:]
|
||||
}
|
||||
return string(ws)
|
||||
}
|
||||
|
||||
func LuaIsWordChar(s string) bool {
|
||||
r, _ := utf8.DecodeRuneInString(s)
|
||||
return IsWordChar(r)
|
||||
}
|
||||
Reference in New Issue
Block a user