generated from broadinstitute/golang-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
selector_helpers.go
51 lines (43 loc) · 1.08 KB
/
selector_helpers.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
package utils
// selector_helpers.go contains simple but frequently-used functions helpful for different data types
// analyzing and validating their individual selectors
import "unicode"
func IsNumeric(selector string) bool {
for _, r := range selector {
if !unicode.IsDigit(r) {
return false
}
}
return true
}
func IsAlphaNumeric(selector string) bool {
for _, r := range selector {
if !unicode.IsDigit(r) && !unicode.IsLetter(r) {
return false
}
}
return true
}
func IsLowerAlphaNumeric(selector string) bool {
for _, r := range selector {
if !unicode.IsDigit(r) && !(unicode.IsLetter(r) && unicode.IsLower(r)) {
return false
}
}
return true
}
func IsAlphaNumericWithHyphens(selector string) bool {
for _, r := range selector {
if !unicode.IsDigit(r) && !unicode.IsLetter(r) && r != '-' {
return false
}
}
return true
}
func IsStartingWithLetter(selector string) bool {
return unicode.IsLetter(rune(selector[0]))
}
func IsEndingWithAlphaNumeric(selector string) bool {
r := rune(selector[len(selector)-1])
return unicode.IsDigit(r) || unicode.IsLetter(r)
}