-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
56 lines (44 loc) · 956 Bytes
/
util.go
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
package cli
import (
"os"
"unicode"
)
func exists(path string) bool {
_, err := os.Stat(path)
return !os.IsNotExist(err)
}
// walk through a nested map, setting option values for the leaves.
func flatten2(in map[string]interface{}, l *Loader, prefix []string) {
for k, v := range in {
path := append(prefix[:], k)
switch x := v.(type) {
case map[string]interface{}:
flatten2(x, l, path)
default:
l.Set(path, v)
}
}
}
// splitIdent splits a Go identifier, such as a function name,
// into multiple parts based on capialization.
func splitIdent(s string) []string {
var parts []string
rs := []rune(s)
start := 0
for i := 1; i < len(s); i++ {
prev := unicode.IsUpper(rs[i-1])
cur := unicode.IsUpper(rs[i])
if prev != cur {
j := i
if prev {
j = i - 1
}
if j > start {
parts = append(parts, string(rs[start:j]))
start = j
}
}
}
parts = append(parts, string(rs[start:]))
return parts
}