2010-07-14 18:26:14 -06: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-02-17 16:44:42 -07:00
|
|
|
// isTSpecial reports whether rune is in 'tspecials' as defined by RFC
|
2011-06-20 08:41:18 -06:00
|
|
|
// 1521 and RFC 2045.
|
2011-10-25 23:23:54 -06:00
|
|
|
func isTSpecial(r rune) bool {
|
2015-12-22 00:40:47 -07:00
|
|
|
return strings.ContainsRune(`()<>@,;:\"/[]?=`, r)
|
2010-07-14 18:26:14 -06:00
|
|
|
}
|
|
|
|
|
2015-02-17 16:44:42 -07:00
|
|
|
// isTokenChar reports whether rune is in 'token' as defined by RFC
|
2011-06-20 08:41:18 -06:00
|
|
|
// 1521 and RFC 2045.
|
2012-02-13 18:48:28 -07:00
|
|
|
func isTokenChar(r rune) bool {
|
2010-07-14 18:26:14 -06:00
|
|
|
// token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
|
|
|
|
// or tspecials>
|
2011-10-25 23:23:54 -06:00
|
|
|
return r > 0x20 && r < 0x7f && !isTSpecial(r)
|
2010-07-14 18:26:14 -06:00
|
|
|
}
|
|
|
|
|
2015-02-17 16:44:42 -07:00
|
|
|
// isToken reports whether s is a 'token' as defined by RFC 1521
|
2011-08-26 14:55:18 -06:00
|
|
|
// and RFC 2045.
|
2012-02-13 18:48:28 -07:00
|
|
|
func isToken(s string) bool {
|
2011-08-26 14:55:18 -06:00
|
|
|
if s == "" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return strings.IndexFunc(s, isNotTokenChar) < 0
|
|
|
|
}
|