// Parse the string into a erb template
433876
func ParseString(cache bool, data ...string) (TemplateChain, error) {
	all := make([][]byte, len(data))
	for index, d := range data {
		all[index] = []byte(d)
	}
	return Parse(cache, all...)
}
714093
func (p *Parser) parseString() (string, error) {
	tok, pos, lit := p.ScanIgnoreWhitespace()
	if tok != STRING {
		return "", newParseError(tokstr(tok, lit), []string{"string"}, pos)
	}
	return lit, nil
}
1178026
func (t *Template) parseTemplate() (next Node) {
	t.Root = t.newList(t.peek().pos)
	// {{ extends|import stringLiteral }}
	for t.peek().typ != itemEOF {
		delim := t.next()
		if delim.typ == itemText && strings.TrimSpace(delim.val) == "" {
			continue //skips empty text nodes
		}
		if delim.typ == itemLeftDelim {
			token := t.nextNonSpace()
			if token.typ == itemExtends || token.typ == itemImport {
				s := t.expectString("extends|import")
				if token.typ == itemExtends {
					if t.extends != nil {
						t.errorf("Unexpected extends clause, only one extends clause is valid per template")
					} else if len(t.imports) > 0 {
						t.errorf("Unexpected extends clause, all import clause should come after extends clause")
					}
					var err error
					t.extends, err = t.set.getTemplateWhileParsing(t.Name, s)
					if err != nil {
						t.error(err)
					}
				} else {
					tt, err := t.set.getTemplateWhileParsing(t.Name, s)
					if err != nil {
						t.error(err)
					}
					t.imports = append(t.imports, tt)
				}
				t.expect(itemRightDelim, "extends|import")
			} else {
				t.backup2(delim)
				break
			}
		} else {
			t.backup()
			break
		}
	}

	for t.peek().typ != itemEOF {
		switch n := t.textOrAction(); n.Type() {
		case nodeEnd, nodeElse, nodeContent:
			t.errorf("unexpected %s", n)
		default:
			t.Root.append(n)
		}
	}
	return nil
}
308293
func (ns *Namespace) Delimit(seq, delimiter interface{}, last ...interface{}) (template.HTML, error) {
	d, err := cast.ToStringE(delimiter)
	if err != nil {
		return "", err
	}

	var dLast *string
	if len(last) > 0 {
		l := last[0]
		dStr, err := cast.ToStringE(l)
		if err != nil {
			dLast = nil
		}
		dLast = &dStr
	}

	seqv := reflect.ValueOf(seq)
	seqv, isNil := indirect(seqv)
	if isNil {
		return "", errors.New("can't iterate over a nil value")
	}

	var str string
	switch seqv.Kind() {
	case reflect.Map:
		sortSeq, err := ns.Sort(seq)
		if err != nil {
			return "", err
		}
		seqv = reflect.ValueOf(sortSeq)
		fallthrough
	case reflect.Array, reflect.Slice, reflect.String:
		for i := 0; i < seqv.Len(); i++ {
			val := seqv.Index(i).Interface()
			valStr, err := cast.ToStringE(val)
			if err != nil {
				continue
			}
			switch {
			case i == seqv.Len()-2 && dLast != nil:
				str += valStr + *dLast
			case i == seqv.Len()-1:
				str += valStr
			default:
				str += valStr + d
			}
		}

	default:
		return "", fmt.Errorf("can't iterate over %v", seq)
	}

	return template.HTML(str), nil
}
392015
func Parse(w io.Writer, r io.Reader, filename, pkg string) error {
	p := &parser{
		s:           newScanner(r, filename),
		w:           w,
		packageName: pkg,
	}
	return p.parseTemplate()
}
1106664
func (r Render) AddFromString(name, templateString string) *template.Template {
	tmpl := template.Must(template.New(name).Parse(templateString))
	r.Add(name, tmpl)
	return tmpl
}
1155613
func Parse(cache bool, data ...[]byte) (TemplateChain, error) {
	templates := make(TemplateChain, len(data))
	for index, d := range data {
		template, err := parseOne(cache, d)
		if err != nil {
			return nil, err
		}
		templates[index] = template
	}
	return templates, nil
}
340765
func fillStringTemplate(tmpl string, vars interface{}) (string, error) {
	myTemplate := template.Must(template.New("").Parse(tmpl))
	data := new(bytes.Buffer)
	if err := myTemplate.Execute(data, vars); err != nil {
		return "", err
	}
	return data.String(), nil
}
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),
	}

}
1253985
func Template(p Partial) string {
	
	qb422016 := qt422016.AcquireByteBuffer()
	
	WriteTemplate(qb422016, p)
	
	qs422016 := string(qb422016.B)
	
	qt422016.ReleaseByteBuffer(qb422016)
	
	return qs422016


}
871432
func Parse(qStr string) (Q, error) {
	b := []byte(qStr)

	qs, _, err := parseExprList(b)
	if err != nil {
		return nil, err
	}

	q, err := parseOperators(qs)
	if err != nil {
		return nil, err
	}

	return Simplify(q), nil
}
1201755
func (d *DateString) Parse(value string) (time.Time, error) {
	return time.Parse(d.Layout, value)
}
1344590
func (g *Generator) ProcessTemplate(tmplName, tmpl string, data interface{}) error {
	vars := []string{}
	for varName, varValue := range g.vars {
		vars = append(vars, fmt.Sprintf("{{ $%s := %q }}", varName, varValue))
	}

	if len(vars) > 0 {
		tmpl = strings.Join(vars, "\n") + "\n" + tmpl
	}

	t, err := template.New(tmplName).Funcs(g.templateFuncs).Parse(tmpl)
	if err != nil {
		return fmt.Errorf("failed to parse template: %v\n%s", err, tmpl)
	}

	if err := t.Execute(g.body, data); err != nil {
		return fmt.Errorf("failed to execute template: %v", err)
	}

	return nil
}
1130690
func ParseString(s string) (key, value string, err error) {
	s = strings.TrimSpace(s)
	if strings.HasPrefix(s, "#") {
		err = ErrCommentln
		return
	}
	if s == "" {
		err = ErrEmptyln
		return
	}
	if !strings.Contains(s, "=") {
		err = ErrInvalidln
		return
	}

	var (
		buf            bytes.Buffer
		quoteType      rune
		hasEq, inQuo   bool
		mapPos, escPos int = posKey, -1
	)

	for i, r := range s {
		if inQuo {
			if i == escPos {
				switch r {
				case 'n':
					buf.WriteString("\n")
				case 'r':
					buf.WriteString("\r")
				default:
					buf.WriteRune(r)
				}
				continue
			}
			// Mark escapes
			if r == '\\' {
				escPos = i + 1
				continue
			}
		}
		// Check for quote delimiters
		if r == '\'' || r == '"' {
			// Look for closing delimiter
			if inQuo && r == quoteType {
				inQuo = false
				// Don't parse beyond a value's terminating quote
				if mapPos == posVal {
					break
				}
				continue
			}
			// Mark quote as delimiter if at start of key/val
			if !inQuo && buf.Len() == 0 {
				quoteType = r
				inQuo = true
				continue
			}
		}
		// If we're inside quotes and not being escaped,
		// ignore certain tokens.
		if !inQuo {
			// Whitespace is ignored outside quoted content
			if unicode.IsSpace(r) {
				continue
			}
			// Hash indicates a comment segment. Cease parsing.
			if r == '#' {
				break
			}
			// If we are parsing the key, '=' indicates the key is written to buffer.
			// Save the key string, and inc pos to value parsing.
			if mapPos == posKey && r == '=' {
				key = buf.String()
				buf.Reset()
				hasEq = true
				mapPos++
				continue
			}
		}
		buf.WriteRune(r)
	}
	// If we've never encountered a '=', the line is invalid. (probably quoted incorrectly)
	if !hasEq {
		err = ErrInvalidln
		return
	}
	value = buf.String()
	// While unlikely, an unquoted value may begin with a literal quote.
	// This would trigger our escape sequence for the char, but never close the quo delimiter.
	// Prepend the quote we marked to compensate for this.
	if inQuo {
		value = string(quoteType) + value
	}
	return
}
426174
func (tid *TemplateInstanceData) Parse(reader io.ReadSeeker) error {
	err := encoding.Unmarshal(reader, &tid.NumValues, Endianness)
	if err != nil {
		return err
	}
	if tid.NumValues < 0 {
		return fmt.Errorf("Negative number of values in TemplateInstanceData")
	}
	// Cannot definitely not be bigger than MaxSliceSize
	if tid.NumValues > MaxSliceSize {
		return fmt.Errorf("Too many values in TemplateInstanceData")
	}
	// We can now allocate process the values
	tid.Values = make([]Element, tid.NumValues)
	tid.ValueOffsets = make([]int32, tid.NumValues)
	tid.ValDescs = make([]ValueDescriptor, tid.NumValues)
	if tid.NumValues > 0 {
		err = encoding.UnmarshaInitSlice(reader, &tid.ValDescs, Endianness)
		if err != nil {
			return err
		}
	}

	// Parse the values
	for i := int32(0); i < tid.NumValues; i++ {
		tid.Values[i], err = ParseValueReader(tid.ValDescs[i], reader)
		if err != nil {
			log.Errorf("%v : %s", tid.ValDescs[i], err)
			log.DebugDontPanicf("%v : %s", tid.ValDescs[i], err)
		}
	}
	return err
}
754078
func (*parser) parseString(b []byte) string {
	n := 0
	for n < len(b) && b[n] != 0 {
		n++
	}
	return string(b[0:n])
}
353291
func parse(str string, index int) *Pair {
	var key, value string
	if index > 0 {
		key, value = str[:index], str[index+1:]
	} else if index == 0 {
		key, value = "", str[1:]
	} else if index < 0 {
		key, value = str, ""
	}

	return &Pair{Key: key, Value: value}
}