// NewTokenLimiter creates a TokenLimiter with count tokens.
354715
func NewTokenLimiter(count uint) *TokenLimiter {
	tl := &TokenLimiter{count: count, ch: make(chan *Token, count)}
	for i := uint(0); i < count; i++ {
		tl.ch <- &Token{}
	}

	return tl
}
958969
func (g *CookieGenerator) NewToken(raddr net.Addr, origConnID protocol.ConnectionID) ([]byte, error) {
	data, err := asn1.Marshal(token{
		RemoteAddr:               encodeRemoteAddr(raddr),
		OriginalDestConnectionID: origConnID,
		Timestamp:                time.Now().Unix(),
	})
	if err != nil {
		return nil, err
	}
	return g.cookieProtector.NewToken(data)
}
980701
func (s *DefaultSentenceTokenizer) AnnotateTokens(tokens []*Token, annotate ...AnnotateTokens) []*Token {
	for _, ann := range annotate {
		tokens = ann.Annotate(tokens)
	}

	return tokens
}
1155119
func NewTokenStreamWith(input *util.AttributeSource) *TokenStreamImpl {
	return &TokenStreamImpl{
		atts: util.NewAttributeSourceFrom(input),
	}
}
842355
func NewTokenizer(s *Storage, word WordTokenizer, lang PunctStrings) *DefaultSentenceTokenizer {
	annotations := NewAnnotations(s, lang, word)

	tokenizer := &DefaultSentenceTokenizer{
		Storage:       s,
		PunctStrings:  lang,
		WordTokenizer: word,
		Annotations:   annotations,
	}

	return tokenizer
}
1177999
func NewToken(token string) *Token {
	tok := Token{
		Tok:        token,
		reEllipsis: reEllipsis,
		reNumeric:  reNumeric,
		reInitial:  reInitial,
		reAlpha:    reAlpha,
	}

	return &tok
}
59509
func newStandardTokenizer(matchVersion util.Version, input io.RuneReader) *StandardTokenizer {
	ans := &StandardTokenizer{
		Tokenizer:      NewTokenizer(input),
		maxTokenLength: DEFAULT_MAX_TOKEN_LENGTH,
	}
	ans.termAtt = ans.Attributes().Add("CharTermAttribute").(CharTermAttribute)
	ans.offsetAtt = ans.Attributes().Add("OffsetAttribute").(OffsetAttribute)
	ans.posIncrAtt = ans.Attributes().Add("PositionIncrementAttribute").(PositionIncrementAttribute)
	ans.typeAtt = ans.Attributes().Add("TypeAttribute").(TypeAttribute)
	ans.init(matchVersion)
	return ans
}
424613
func tokenFromInt(iv int32) lex.Token {
	t, ok := lex.TokenNameMap[lex.TokenType(iv)]
	if ok {
		return lex.Token{T: t.T, V: t.Description}
	}
	return lex.Token{}
}
1189475
func NewToken(t TokenType, word []rune, pos Position) *Token {
	// ensure the type is valid
	if t < ILLEGAL || t > BAD {
		t = BAD
	}

	// return the token
	return &Token{Type: t, Word: word, Position: pos}
}
616479
func (p *Parser) ParseOptionalTokenAndInt(t Token) (int, error) {
	// Check if the token exists.
	if tok, _, _ := p.ScanIgnoreWhitespace(); tok != t {
		p.Unscan()
		return 0, nil
	}

	// Scan the number.
	tok, pos, lit := p.ScanIgnoreWhitespace()
	if tok != INTEGER {
		return 0, newParseError(tokstr(tok, lit), []string{"integer"}, pos)
	}

	// Parse number.
	n, _ := strconv.ParseInt(lit, 10, 64)
	if n < 0 {
		msg := fmt.Sprintf("%s must be >= 0", t.String())
		return 0, &ParseError{Message: msg, Pos: pos}
	}

	return int(n), nil
}
57982
func NewTrackToken(g *libkb.GlobalContext, arg *TrackTokenArg) *TrackToken {
	if arg.Options.SigVersion == nil || libkb.SigVersion(*arg.Options.SigVersion) == libkb.KeybaseNullSigVersion {
		tmp := keybase1.SigVersion(libkb.GetDefaultSigVersion(g))
		arg.Options.SigVersion = &tmp
	}

	return &TrackToken{
		arg:          arg,
		Contextified: libkb.NewContextified(g),
	}
}
406719
func (t *templateHandler) NewTextTemplate() tpl.TemplateParseFinder {
	t.mu.Lock()
	defer t.mu.Unlock()

	tt := &textTemplate{t: texttemplate.New("")}
	t.extTextTemplates = append(t.extTextTemplates, tt)

	return struct {
		tpl.TemplateParser
		tpl.TemplateLookup
		tpl.TemplateLookupVariant
	}{
		tt,
		tt,
		new(nopLookupVariant),
	}

}
835700
func newTokenInjector(meta *metadata.Client, acc string) func(*http.Request) error {
	if acc == "" {
		acc = "default"
	}
	acc = url.PathEscape(acc)
	return func(req *http.Request) error {
		aud := fmt.Sprintf("%s://%s", req.URL.Scheme, req.URL.Host)
		aud = url.QueryEscape(aud)
		// TODO(smut): Cache the token and reuse if not yet expired.
		// Currently the only user of this package only makes one
		// request per boot so caching isn't too important yet.
		tok, err := meta.Get(fmt.Sprintf(tokMetadata, acc, aud))
		if err != nil {
			return err
		}
		req.Header.Set(vmtoken.Header, tok)
		return nil
	}
}
217537
func NewTokenFilter(input TokenStream) *TokenFilter {
	return &TokenFilter{
		TokenStreamImpl: NewTokenStreamWith(input.Attributes()),
		input:           input,
	}
}
698868
func NewTokenGenerator(s string, err error) TokenGenerator {
	return TokenGenerator{
		TokenFn: func() (string, error) {
			return s, err
		},
	}
}
392072
func NewTokenGroupAdder(auth authenticator.Token, groups []string) authenticator.Token {
	return &TokenGroupAdder{auth, groups}
}
1265685
func parseMacroToken(p *parser, t *token) (string, error) {
	return parseMacro(p, t.value)
}