File: lua.go

package info (click to toggle)
micro 2.0.15-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,828 kB
  • sloc: sh: 247; makefile: 77; xml: 53
file content (41 lines) | stat: -rw-r--r-- 843 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package util

// 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 := DecodeCharacterInString(str)

		str = str[size:]

		if i == runeidx {
			return string(r)
		}

		i++
	}
	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 := DecodeCharacterInString(s)
		if r == ' ' || r == '\t' {
			ws = append(ws, byte(r))
		} else {
			break
		}

		s = s[size:]
	}
	return string(ws)
}

// LuaIsWordChar returns true if the first rune in a string is a word character
func LuaIsWordChar(s string) bool {
	r, _, _ := DecodeCharacterInString(s)
	return IsWordChar(r)
}