2010-12-03 05:34:57 +01: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 01:59:47 +01:00
|
|
|
// isTSpecial reports whether rune is in 'tspecials' as defined by RFC
|
2011-09-16 17:47:21 +02:00
|
|
|
// 1521 and RFC 2045.
|
2011-12-02 20:34:41 +01:00
|
|
|
func isTSpecial(r rune) bool {
|
|
|
|
return strings.IndexRune(`()<>@,;:\"/[]?=`, r) != -1
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
|
|
|
|
2015-10-31 01:59:47 +01:00
|
|
|
// isTokenChar reports whether rune is in 'token' as defined by RFC
|
2011-09-16 17:47:21 +02:00
|
|
|
// 1521 and RFC 2045.
|
2012-03-02 17:38:43 +01:00
|
|
|
func isTokenChar(r rune) bool {
|
2010-12-03 05:34:57 +01:00
|
|
|
// token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
|
|
|
|
// or tspecials>
|
2011-12-02 20:34:41 +01:00
|
|
|
return r > 0x20 && r < 0x7f && !isTSpecial(r)
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
|
|
|
|
2015-10-31 01:59:47 +01:00
|
|
|
// isToken reports whether s is a 'token' as defined by RFC 1521
|
2011-10-27 01:57:58 +02:00
|
|
|
// and RFC 2045.
|
2012-03-02 17:38:43 +01:00
|
|
|
func isToken(s string) bool {
|
2011-10-27 01:57:58 +02:00
|
|
|
if s == "" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return strings.IndexFunc(s, isNotTokenChar) < 0
|
|
|
|
}
|