github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/resource/api/internal/mime/grammar.go (about)

     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  
     5  //+build !go1.6
     6  
     7  // TODO(natefinch) remove this once we support building on go 1.6 for all platforms.
     8  // This code was copied from the Go 1.6 sourcecode.
     9  
    10  package mime
    11  
    12  import (
    13  	"strings"
    14  )
    15  
    16  // isTSpecial reports whether rune is in 'tspecials' as defined by RFC
    17  // 1521 and RFC 2045.
    18  func isTSpecial(r rune) bool {
    19  	return strings.ContainsRune(`()<>@,;:\"/[]?=`, r)
    20  }
    21  
    22  // isTokenChar reports whether rune is in 'token' as defined by RFC
    23  // 1521 and RFC 2045.
    24  func isTokenChar(r rune) bool {
    25  	// token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
    26  	//             or tspecials>
    27  	return r > 0x20 && r < 0x7f && !isTSpecial(r)
    28  }
    29  
    30  // isToken reports whether s is a 'token' as defined by RFC 1521
    31  // and RFC 2045.
    32  func isToken(s string) bool {
    33  	if s == "" {
    34  		return false
    35  	}
    36  	return strings.IndexFunc(s, isNotTokenChar) < 0
    37  }