grammar.go 828 B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2010 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 mime
  5. import (
  6. "strings"
  7. )
  8. // isTSpecial reports whether rune is in 'tspecials' as defined by RFC
  9. // 1521 and RFC 2045.
  10. func isTSpecial(r rune) bool {
  11. return strings.ContainsRune(`()<>@,;:\"/[]?=`, r)
  12. }
  13. // isTokenChar reports whether rune is in 'token' as defined by RFC
  14. // 1521 and RFC 2045.
  15. func isTokenChar(r rune) bool {
  16. // token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
  17. // or tspecials>
  18. return r > 0x20 && r < 0x7f && !isTSpecial(r)
  19. }
  20. // isToken reports whether s is a 'token' as defined by RFC 1521
  21. // and RFC 2045.
  22. func isToken(s string) bool {
  23. if s == "" {
  24. return false
  25. }
  26. return strings.IndexFunc(s, isNotTokenChar) < 0
  27. }