Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathmap.go
More file actions
Latest commit
74 lines (68 loc) · 2.04 KB
/
Copy pathmap.go
File metadata and controls
74 lines (68 loc) · 2.04 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
package devstatscode
import (
"sort"
"strings"
)
// SkipEmpty - skip one element arrays contining only empty string
// This is what strings.Split() returns for empty input
// We expect empty array or empty map returned in such cases
funcSkipEmpty(arr []string) []string {
iflen(arr) !=1||len(arr) ==1&&arr[0] !="" {
returnarr
}
return []string{}
}
// StringsMapToArray this is a function that calls given function for all array items and returns array of items processed by this func
// Example call: lib.StringsMapToArray(func(x string) string { return strings.TrimSpace(x) }, []string{" a", " b ", "c "})
funcStringsMapToArray(ffunc(string) string, strArr []string) []string {
strArr=SkipEmpty(strArr)
outArr:=make([]string, len(strArr))
forindex, str:=rangestrArr {
outArr[index] =f(str)
}
returnoutArr
}
// StringsMapToSet this is a function that calls given function for all array items and returns set of items processed by this func
// Example call: lib.StringsMapToSet(func(x string) string { return strings.TrimSpace(x) }, []string{" a", " b ", "c "})
funcStringsMapToSet(ffunc(string) string, strArr []string) map[string]struct{} {
strArr=SkipEmpty(strArr)
outSet:=make(map[string]struct{})
for_, str:=rangestrArr {
outSet[f(str)] =struct{}{}
}
returnoutSet
}
// StringsSetKeys - returns all keys from string map
funcStringsSetKeys(setmap[string]struct{}) []string {
outArr:=make([]string, len(set))
index:=0
forkey:=rangeset {
outArr[index] =key
index++
}
sort.Strings(outArr)
returnoutArr
}
// MapFromString - returns maps from string formatted as map[k1:v1 k2:v2 k3:v3 ...]
funcMapFromString(strstring) map[string]string {
iflen(str) <6 {
returnnil
}
l:=len(str)
ifstr[:4] !="map["||str[l-1:l] !="]" {
returnnil
}
str=str[4 : l-1]
ary:=strings.Split(str, " ")
varresmap[string]string
for_, data:=rangeary {
d:=strings.Split(data, ":")
iflen(d) ==2 {
ifres==nil {
res=make(map[string]string)
}
res[d[0]] =d[1]
}
}
returnres
}