-
Notifications
You must be signed in to change notification settings - Fork 0
/
judgment.go
56 lines (48 loc) · 986 Bytes
/
judgment.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
package strings
// Is c an ASCII lower-case letter?
func IsASCIILower(c byte) bool {
return 'a' <= c && c <= 'z'
}
func IsASCIIUpper(c byte) bool {
return 'A' <= c && c <= 'Z'
}
func IsASCIILetter(c byte) bool {
return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')
}
// Is c an ASCII digit?
func IsASCIIDigit(c byte) bool {
return '0' <= c && c <= '9'
}
// 有一个匹配成功就返回true
func HasPrefixes(s string, prefixes []string) bool {
for _, prefix := range prefixes {
if len(s) >= len(prefix) && s[0:len(prefix)] == prefix {
return true
}
}
return false
}
func IsASCIILowers(s string) bool {
for _, c := range s {
if 'a' < c || c > 'z' {
return false
}
}
return true
}
func IsASCIIUppers(s string) bool {
for _, c := range s {
if 'A' < c || c > 'Z' {
return false
}
}
return true
}
func IsASCIILetters(s string) bool {
for _, c := range s {
if c < 'A' || c > 'z' || (c > 'Z' && c < 'a') {
return false
}
}
return true
}