OSDN Git Service

new repo
[bytom/vapor.git] / vendor / golang.org / x / text / secure / precis / class.go
1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package precis
6
7 import (
8         "unicode/utf8"
9 )
10
11 // TODO: Add contextual character rules from Appendix A of RFC5892.
12
13 // A class is a set of characters that match certain derived properties. The
14 // PRECIS framework defines two classes: The Freeform class and the Identifier
15 // class. The freeform class should be used for profiles where expressiveness is
16 // prioritized over safety such as nicknames or passwords. The identifier class
17 // should be used for profiles where safety is the first priority such as
18 // addressable network labels and usernames.
19 type class struct {
20         validFrom property
21 }
22
23 // Contains satisfies the runes.Set interface and returns whether the given rune
24 // is a member of the class.
25 func (c class) Contains(r rune) bool {
26         b := make([]byte, 4)
27         n := utf8.EncodeRune(b, r)
28
29         trieval, _ := dpTrie.lookup(b[:n])
30         return c.validFrom <= property(trieval)
31 }
32
33 var (
34         identifier = &class{validFrom: pValid}
35         freeform   = &class{validFrom: idDisOrFreePVal}
36 )