-
Notifications
You must be signed in to change notification settings - Fork 10
/
chars.go
63 lines (51 loc) · 1.72 KB
/
chars.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
57
58
59
60
61
62
63
// Copyright 2012-2014, Rolf Veen and contributors.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ogdl
import (
"bytes"
"unicode"
)
// IsTextChar returns true for all integers > 32 and
// are not OGDL separators (parenthesis and comma)
func isTextChar(c int) bool {
return c > 32 && c != '(' && c != ')' && c != ','
}
// IsEndChar returns true for all integers < 32 that are not newline,
// carriage return or tab.
func isEndChar(c int) bool {
return c < 32 && c != '\t' && c != '\n' && c != '\r'
}
// IsBreakChar returns true for 10 and 13 (newline and carriage return)
func isBreakChar(c int) bool {
return c == 10 || c == 13
}
// IsSpaceChar returns true for space and tab
func isSpaceChar(c int) bool {
return c == 32 || c == 9
}
// IsTemplateTextChar returns true for all not END chars and not $
func isTemplateTextChar(c int) bool {
return !isEndChar(c) && c != '$'
}
// IsOperatorChar returns true for all operator characters used in OGDL
// expressions (those parsed by NewExpression).
func isOperatorChar(c int) bool {
if c < 0 {
return false
}
return bytes.IndexByte([]byte("+-*/%&|!<>=~^"), byte(c)) != -1
}
// ---- Following functions are the only ones that depend on Unicode --------
// IsLetter returns true if the given character is a letter, as per Unicode.
func isLetter(c int) bool {
return unicode.IsLetter(rune(c)) || c == '_'
}
// IsDigit returns true if the given character a numeric digit, as per Unicode.
func isDigit(c int) bool {
return unicode.IsDigit(rune(c))
}
// IsTokenChar returns true for letters, digits and _ (as per Unicode).
func isTokenChar(c int) bool {
return unicode.IsLetter(rune(c)) || unicode.IsDigit(rune(c)) || c == '_'
}