| 1 |
package util |
| 2 |
|
| 3 |
// LuaRuneAt is a helper function for lua plugins to return the rune |
| 4 |
// at an index within a string |
| 5 |
func LuaRuneAt(str string, runeidx int) string { |
| 6 |
i := 0 |
| 7 |
for len(str) > 0 { |
| 8 |
r, _, size := DecodeCharacterInString(str) |
| 9 |
|
| 10 |
str = str[size:] |
| 11 |
|
| 12 |
if i == runeidx { |
| 13 |
return string(r) |
| 14 |
} |
| 15 |
|
| 16 |
i++ |
| 17 |
} |
| 18 |
return "" |
| 19 |
} |
| 20 |
|
| 21 |
// LuaGetLeadingWhitespace returns the leading whitespace of a string (used by lua plugins) |
| 22 |
func LuaGetLeadingWhitespace(s string) string { |
| 23 |
ws := []byte{} |
| 24 |
for len(s) > 0 { |
| 25 |
r, _, size := DecodeCharacterInString(s) |
| 26 |
if r == ' ' || r == '\t' { |
| 27 |
ws = append(ws, byte(r)) |
| 28 |
} else { |
| 29 |
break |
| 30 |
} |
| 31 |
|
| 32 |
s = s[size:] |
| 33 |
} |
| 34 |
return string(ws) |
| 35 |
} |
| 36 |
|
| 37 |
// LuaIsWordChar returns true if the first rune in a string is a word character |
| 38 |
func LuaIsWordChar(s string) bool { |
| 39 |
r, _, _ := DecodeCharacterInString(s) |
| 40 |
return IsWordChar(r) |
| 41 |
} |