-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
contains.go
55 lines (46 loc) Β· 1.02 KB
/
contains.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
package rnd
// ContainsUID checks if a slice of strings contains ContainsUID only.
func ContainsUID(s []string, prefix byte) bool {
if len(s) < 1 {
return false
}
for _, id := range s {
switch prefix {
case 0:
if !IsUnique(id, prefix) {
return false
}
default:
if !IsUID(id, prefix) {
return false
}
}
}
return true
}
// ContainsType checks if a slice of strings contains only random IDs of a given type and returns it.
func ContainsType(ids []string) (idType Type, idPrefix byte) {
if len(ids) < 1 {
return TypeEmpty, PrefixNone
}
idType = TypeUnknown
idPrefix = PrefixNone
for _, id := range ids {
t, p := IdType(id)
if t == TypeUnknown {
return TypeUnknown, PrefixNone
} else if idType == TypeUnknown {
idType = t
} else if idType != t {
return TypeMixed, PrefixNone
}
if t != TypeUID {
continue
} else if idPrefix == PrefixNone {
idPrefix = p
} else if idPrefix != PrefixMixed && idPrefix != p {
idPrefix = PrefixMixed
}
}
return idType, idPrefix
}