-
Notifications
You must be signed in to change notification settings - Fork 88
/
util.go
62 lines (48 loc) · 934 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
57
58
59
60
61
62
package util
import (
"bytes"
"net/url"
)
func IsURL(str string) bool {
_, err := url.ParseRequestURI(str)
if err != nil {
return false
}
return true
}
func CommonSlicePrefix(first []string, second []string) []string {
common := []string{}
for i, a := range first {
if i+1 > len(second) {
return common
}
if first[i] != second[i] {
return common
}
common = append(common, a)
}
return common
}
func SplitStringOnLen(str string, maxLength int) ([]string, error) {
if maxLength >= len(str) {
return []string{str}, nil
}
work := ""
result := []string{}
runes := bytes.Runes([]byte(str))
for i, r := range runes {
work = work + string(r)
if (i+1)%maxLength == 0 {
result = append(result, work)
work = ""
} else if i+1 == len(runes) {
result = append(result, work)
}
}
return result, nil
}
func IntPointer(x int) *int64 {
var xout int64
xout = int64(x)
return &xout
}