You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

37 lines
1.1 KiB

  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. package precis
  5. import (
  6. "unicode/utf8"
  7. )
  8. // TODO: Add contextual character rules from Appendix A of RFC5892.
  9. // A class is a set of characters that match certain derived properties. The
  10. // PRECIS framework defines two classes: The Freeform class and the Identifier
  11. // class. The freeform class should be used for profiles where expressiveness is
  12. // prioritized over safety such as nicknames or passwords. The identifier class
  13. // should be used for profiles where safety is the first priority such as
  14. // addressable network labels and usernames.
  15. type class struct {
  16. validFrom property
  17. }
  18. // Contains satisfies the runes.Set interface and returns whether the given rune
  19. // is a member of the class.
  20. func (c class) Contains(r rune) bool {
  21. b := make([]byte, 4)
  22. n := utf8.EncodeRune(b, r)
  23. trieval, _ := dpTrie.lookup(b[:n])
  24. return c.validFrom <= property(trieval)
  25. }
  26. var (
  27. identifier = &class{validFrom: pValid}
  28. freeform = &class{validFrom: idDisOrFreePVal}
  29. )