2010-12-03 04:34:57 +00:00
|
|
|
// Copyright 2010 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package mime
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2015-10-31 00:59:47 +00:00
|
|
|
// isTSpecial reports whether rune is in 'tspecials' as defined by RFC
|
2011-09-16 15:47:21 +00:00
|
|
|
// 1521 and RFC 2045.
|
2011-12-02 19:34:41 +00:00
|
|
|
func isTSpecial(r rune) bool {
|
2016-07-22 18:15:38 +00:00
|
|
|
return strings.ContainsRune(`()<>@,;:\"/[]?=`, r)
|
2010-12-03 04:34:57 +00:00
|
|
|
}
|
|
|
|
|
2015-10-31 00:59:47 +00:00
|
|
|
// isTokenChar reports whether rune is in 'token' as defined by RFC
|
2011-09-16 15:47:21 +00:00
|
|
|
// 1521 and RFC 2045.
|
2012-03-02 16:38:43 +00:00
|
|
|
func isTokenChar(r rune) bool {
|
2010-12-03 04:34:57 +00:00
|
|
|
// token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
|
|
|
|
// or tspecials>
|
2011-12-02 19:34:41 +00:00
|
|
|
return r > 0x20 && r < 0x7f && !isTSpecial(r)
|
2010-12-03 04:34:57 +00:00
|
|
|
}
|
|
|
|
|
2015-10-31 00:59:47 +00:00
|
|
|
// isToken reports whether s is a 'token' as defined by RFC 1521
|
2011-10-26 23:57:58 +00:00
|
|
|
// and RFC 2045.
|
2012-03-02 16:38:43 +00:00
|
|
|
func isToken(s string) bool {
|
2011-10-26 23:57:58 +00:00
|
|
|
if s == "" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return strings.IndexFunc(s, isNotTokenChar) < 0
|
|
|
|
}
|