/
runes.go
47 lines (37 loc) · 973 Bytes
/
runes.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
/*
Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
Use of this source code is governed by a MIT license that can be found in the LICENSE file.
*/
package selector
import "unicode"
func isWhitespace(ch rune) bool {
return unicode.IsSpace(ch)
}
func isNameSymbol(ch rune) bool {
switch ch {
case Dot, Dash, Underscore:
return true
}
return false
}
func isOperatorSymbol(ch rune) bool {
return ch == Bang || ch == Equal
}
func isSymbol(ch rune) bool {
return (int(ch) >= int(Bang) && int(ch) <= int(ForwardSlash)) ||
(int(ch) >= int(Colon) && int(ch) <= int(At)) ||
(int(ch) >= int(OpenBracket) && int(ch) <= int(BackTick)) ||
(int(ch) >= int(OpenCurly) && int(ch) <= int(Tilde))
}
func isAlpha(ch rune) bool {
return !isWhitespace(ch) && !unicode.IsControl(ch) && !isSymbol(ch)
}
func isDNSAlpha(ch rune) bool {
if unicode.IsDigit(ch) {
return true
}
if unicode.IsLetter(ch) {
return unicode.IsLower(ch)
}
return false
}