// JS provides a Twig-compatible javascript escaper.
488344
func JS(in string) string {
	var out = &bytes.Buffer{}
	for _, c := range in {
		if (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57) || c == 44 || c == 46 || c == 95 {
			// a-zA-Z0-9,._
			out.WriteRune(c)
		} else {
			// UTF-8
			fmt.Fprintf(out, "\\u%04X", c)
		}
	}
	return out.String()
}
454329
func (r *Render) Html(w http.ResponseWriter, status int, name string, binding interface{}) error {
	if r.opt.IsDevelopment {
		r.compile()
	}

	if tSet, ok := r.templates[name]; !ok {
		return fmt.Errorf("Cannot find template %q in Render", name)
	} else {
		if r.opt.UseBufPool {
			buf := r.bufPool.Get()
			if err := tSet.template.Execute(buf, binding); err != nil {
				return fmt.Errorf("Template execution error, %s", err)
			}
			w.Header().Set("Content-Type", kContentHtml+kContentCharset)
			w.WriteHeader(status)
			_, err := buf.WriteTo(w)
			r.bufPool.Put(buf)
			return err
		} else {
			out := new(bytes.Buffer)
			if err := tSet.template.Execute(out, binding); err != nil {
				return fmt.Errorf("Template execution error, %s", err)
			}
			w.Header().Set("Content-Type", kContentHtml+kContentCharset)
			w.WriteHeader(status)
			_, err := io.Copy(w, out)
			return err
		}
	}
}
537687
func (e *EventSub) DOM(dom *js.Object) {
	e.Offload()
	e.dom = dom
	e.jslink = func(o *js.Object) { e.TriggerMatch(&EventObject{o}) }
	e.dom.Call("addEventListener", e.Type(), e.jslink, true)
}
225732
func magic(t reflect.Type, s string) (i interface{}, err error) {
	switch t.Kind() {
	case reflect.Int:
		i, err = strconv.Atoi(s)
	case reflect.String:
		i = s
	case reflect.Ptr:
		if t.Elem().String() != "regexp.Regexp" {
			err = fmt.Errorf("does not support %s", t.Elem().String())
			return
		}
		i, err = regexp.Compile(s)
	default:
		err = fmt.Errorf("does not support %s", t.Kind().String())
	}
	return
}
1137256
func Escape(formatter Formatter) Formatter {
	return func(buffer Buffer, event *cue.Event) {
		tmp := GetBuffer()
		defer ReleaseBuffer(tmp)

		formatter(tmp, event)
		runes := []rune(string(tmp.Bytes()))
		for _, r := range runes {
			switch {
			case r == ' ':
				buffer.AppendRune(r)
			case unicode.IsControl(r), unicode.IsSpace(r):
				quoted := strconv.QuoteRune(r)
				buffer.AppendString(quoted[1 : len(quoted)-1])
			default:
				buffer.AppendRune(r)
			}
		}
	}
}
1234499
func (fn *ScriptFunction) Script(script *Script) *ScriptFunction {
	fn.script = script
	return fn
}
1030939
func (p *Params) Escape(key string) (string, error) {
	if len(key) == 0 {
		return "", errors.New("not exist")
	}
	if key[0] != ':' && key[0] != '*' {
		key = ":" + key
	}

	for _, v := range *p {
		if v.Name == key {
			return template.HTMLEscapeString(v.Value), nil
		}
	}
	return "", errors.New("not exist")
}
1209002
func EscapeString(ch *Changeset, fields ...string) {
	for _, field := range fields {
		ApplyString(ch, field, html.EscapeString)
	}
}
701044
func (l Locale) Tr(format string, args ...interface{}) string {
	return Tr(l.Lang, format, args...)
}
867592
func (t *File_Template) Render(params map[string]*Value) (string, error) {
	sSet := stringset.New(len(params))
	replacementSlice := make([]string, 0, len(t.Param)*2)
	for k, param := range t.Param {
		replacementSlice = append(replacementSlice, k)
		if newVal, ok := params[k]; ok {
			if err := param.Accepts(newVal); err != nil {
				return "", fmt.Errorf("param %q: %s", k, err)
			}
			sSet.Add(k)
			replacementSlice = append(replacementSlice, newVal.JSONRender())
		} else if param.Default != nil {
			replacementSlice = append(replacementSlice, param.Default.JSONRender())
		} else {
			return "", fmt.Errorf("param %q: missing", k)
		}
	}
	if len(params) != sSet.Len() {
		unknown := make([]string, 0, len(params))
		for k := range params {
			if !sSet.Has(k) {
				unknown = append(unknown, k)
			}
		}
		sort.Strings(unknown)
		return "", fmt.Errorf("unknown parameters: %q", unknown)
	}

	r := strings.NewReplacer(replacementSlice...)

	return r.Replace(t.Body), nil
}
496958
func (i18n *I18n) T(locale, key string, args ...interface{}) template.HTML {
	var (
		value           = i18n.value
		translationKey  = key
		fallbackLocales = i18n.fallbackLocales
	)

	if locale == "" {
		locale = Default
	}

	if locales, ok := i18n.FallbackLocales[locale]; ok {
		fallbackLocales = append(fallbackLocales, locales...)
	}
	fallbackLocales = append(fallbackLocales, Default)

	if i18n.scope != "" {
		translationKey = strings.Join([]string{i18n.scope, key}, ".")
	}

	var translation Translation
	if err := i18n.cacheStore.Unmarshal(cacheKey(locale, key), &translation); err != nil || translation.Value == "" {
		for _, fallbackLocale := range fallbackLocales {
			if err := i18n.cacheStore.Unmarshal(cacheKey(fallbackLocale, key), &translation); err == nil && translation.Value != "" {
				break
			}
		}

		if translation.Value == "" {
			// Get default translation if not translated
			if err := i18n.cacheStore.Unmarshal(cacheKey(Default, key), &translation); err != nil || translation.Value == "" {
				// If not initialized
				var defaultBackend Backend
				if len(i18n.Backends) > 0 {
					defaultBackend = i18n.Backends[0]
				}
				translation = Translation{Key: translationKey, Value: value, Locale: locale, Backend: defaultBackend}

				// Save translation
				i18n.SaveTranslation(&translation)
			}
		}
	}

	if translation.Value != "" {
		value = translation.Value
	} else {
		value = key
	}

	if str, err := cldr.Parse(locale, value, args...); err == nil {
		value = str
	}

	return template.HTML(value)
}
1332790
func LiteralPrefix(s *syntax.Regexp) string {
	// traverse the left-most branch in the parse tree as long as the
	// node represents a concatenation
	for s != nil && s.Op == syntax.OpConcat {
		if len(s.Sub) < 1 {
			return ""
		}

		s = s.Sub[0]
	}

	if s.Op == syntax.OpLiteral {
		return string(s.Rune)
	}

	return "" // no literal prefix
}
572583
func (f *field) escape() field {
	pos := 0
	for i := 0; i < len(f.str); i++ {
		c := f.str[i]
		if i+1 < len(f.str) && f.str[i] == '\\' {
			c = f.escapeChar(f.str[i+1])
			i++
		}

		f.str[pos] = c
		pos++
	}
	return field{f.str[:pos], f.maybeNull, f.enclosed}
}
173695
func (g *Group) Rune() *Statement {
	// notest
	s := Rune()
	g.items = append(g.items, s)
	return s
}
905228
func Eval(js string, expr string, opts ...string) ([]json.RawMessage, error) {
	jq, err := New(bytes.NewReader([]byte(js)), expr, opts...)
	if err != nil {
		return nil, err
	}

	ret := make([]json.RawMessage, 0, 16)
	for {
		next, err := jq.Next()
		switch err {
		case nil:
			ret = append(ret, next)
		case io.EOF:
			return ret, nil
		default:
			return ret, err
		}
	}
	panic("unreachable") // for go 1.0
}
761991
func (f *Fpdf) escape(s string) string {
	s = strings.Replace(s, "\\", "\\\\", -1)
	s = strings.Replace(s, "(", "\\(", -1)
	s = strings.Replace(s, ")", "\\)", -1)
	s = strings.Replace(s, "\r", "\\r", -1)
	return s
}
1194727
func (p *WebPage) EvaluateJavaScript(script string) (interface{}, error) {
	var resp struct {
		ReturnValue interface{} `json:"returnValue"`
	}
	if err := p.ref.process.doJSON("POST", "/webpage/EvaluateJavaScript", map[string]interface{}{"ref": p.ref.id, "script": script}, &resp); err != nil {
		return nil, err
	}
	return resp.ReturnValue, nil
}