-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings.go
More file actions
85 lines (73 loc) · 1.44 KB
/
Copy pathstrings.go
File metadata and controls
85 lines (73 loc) · 1.44 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"fmt"
"strings"
)
var (
globChars = []rune{'*', '?', '!', '{', '}'}
)
type state struct {
on bool
}
func (t *state) toggle(src rune, match rune, disableOnNoMatch bool) {
if disableOnNoMatch == true {
if src != match {
t.on = false
} else {
t.on = !t.on
}
} else if src == match {
t.on = !t.on
}
}
func lupGroup(i int) (s string) {
return fmt.Sprintf("##LUP_GROUP_%d##", i)
}
func isHidden(text string) (b bool, s string) {
if strings.HasPrefix(text, hider) {
b = true
s = text[2:]
} else {
s = text
}
return b, s
}
func addSlashes(word string) string {
delimiter := '@'
word = strings.Replace(word, string(delimiter), "\\"+string(delimiter), -1)
word = strings.Replace(word, ",", "\\,", -1)
return word
}
func stripSlashes(word string) string {
word = strings.Replace(word, "\\"+string(delimiter), string(delimiter), -1)
word = strings.Replace(word, "\\,", ",", -1)
return word
}
func runeIn(group []rune, r rune) (b bool) {
for _, x := range group {
if string(x) == string(r) {
b = true
}
}
return b
}
func hasGlobs(text string) (b bool) {
for _, c := range text {
if runeIn(globChars, c) {
b = true
}
}
return b
}
func isEscaped(text string, n int) (b bool) {
if n > 0 && text[n-1] == '\\' {
b = true
}
return b
}
func unescapeGlobChars(text string) string {
for _, char := range globChars {
text = strings.Replace(text, "\\"+string(char), string(char), -1)
}
return text
}