-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
65 lines (59 loc) · 1006 Bytes
/
utils.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
57
58
59
60
61
62
63
64
65
package main
import (
"strings"
)
func split(str, sep string, size int) []string {
arr := make([]string, 0, size)
for {
idx := strings.Index(str, sep)
if idx < 0 {
arr = append(arr, str)
break
}
arr = append(arr, str[:idx])
str = str[idx+1:]
}
return arr
}
func appendbyte(b []byte, b1 []byte) []byte {
b2 := make([]byte, len(b)+len(b1))
copy(b2, b)
var j int
for i := len(b); i < len(b)+len(b1); i++ {
b2[i] = b1[j]
j++
}
return b2
}
func splitFiles(str string) []string {
if !strings.Contains(str, " ") {
return []string{str}
}
i := strings.Count(str, " ")
// # emoji_suggestion.yaml # opencc/*.*
arr := make([]string, 0, i+1)
var skip bool
for {
j := strings.Index(str, " ")
if j < 0 {
if !skip {
arr = append(arr, str)
}
break
}
if skip {
str = str[j+1:]
skip = false
continue
}
if str[:j] == "#" {
skip = true
} else {
if str[0] != '#' {
arr = append(arr, str[:j])
}
}
str = str[j+1:]
}
return arr
}