-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattributes.go
More file actions
32 lines (28 loc) · 860 Bytes
/
attributes.go
File metadata and controls
32 lines (28 loc) · 860 Bytes
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
package testsuite
import (
"github.com/di-wu/parser"
"github.com/di-wu/parser/op"
)
var (
// More info: https://tools.ietf.org/html/rfc5234#appendix-B
// alpha = %x41-5A / %x61-7A ; A-Z / a-z
alpha = op.Or{
parser.CheckRuneRange('a', 'z'),
parser.CheckRuneRange('A', 'Z'),
}
// digit = %x30-39 ; 0-9
digit = parser.CheckRuneRange('0', '9')
// More info: https://tools.ietf.org/html/rfc7643#section-2.1
// nameChar = "$" / "-" / "_" / DIGIT / ALPHA
nameChar = op.Or{'$', '-', '_', digit, alpha}
// attrName = ALPHA *(nameChar)
attrName = op.And{op.Or{'$', alpha}, op.MinZero(nameChar)}
)
// IsAttributeName checks whether the given string is a valid attribute name.
// More info: https://tools.ietf.org/html/rfc7643#section-2.1
func IsAttributeName(s string) bool {
if err := is(attrName, s); err != nil {
return false
}
return true
}