// EscapeGlobString returns an escaped version of the passed string, ensuring a literal match of its components.
// As distinct to EscapeGlobComponent, it will not escape the separator
551317
func EscapeGlobString(gs string, options *Options) string {
	if options == nil {
		options = DefaultOptions
	}

	runesToEscapeMap := make(map[string]bool, len(expanders))
	for _, r := range expanders {
		runesToEscapeMap[string(r)] = true
	}

	scanner := bufio.NewScanner(strings.NewReader(gs))
	scanner.Split(separatorsScanner(expanders))
	buf := new(bytes.Buffer)
	for scanner.Scan() {
		part := scanner.Text()
		if runesToEscapeMap[part] {
			buf.WriteRune(Escaper)
		}
		buf.WriteString(part)
	}

	return buf.String()
}
857762
func EscapeAssertion(s string) string {
	//Replace the first dot, because it can't be recognized by the regexp.
	if (strings.HasPrefix(s, "r") || strings.HasPrefix(s, "p")) {
		s = strings.Replace(s, ".", "_",1)
	}
	var regex = regexp.MustCompile(`(\|| |=|\)|\(|&|<|>|,|\+|-|!|\*|\/)(r|p)\.`)
	s = regex.ReplaceAllStringFunc(s, func(m string) string {
		return strings.Replace(m, ".", "_", 1)
	})
	return s
}
427965
func (s *TranslateFile) TranslateColumnToString(index string, value uint64) (string, error) {
	s.mu.RLock()
	if idx := s.cols[index]; idx != nil {
		if ret, ok := idx.keyByID(value); ok {
			s.mu.RUnlock()
			return string(ret), nil
		}
	}
	s.mu.RUnlock()
	return "", nil
}
808645
func (stream *Stream) WriteStringWithHTMLEscaped(s string) {
	valLen := len(s)
	stream.buf = append(stream.buf, '"')
	// write string, the fast path, without utf8 and escape support
	i := 0
	for ; i < valLen; i++ {
		c := s[i]
		if c < utf8.RuneSelf && htmlSafeSet[c] {
			stream.buf = append(stream.buf, c)
		} else {
			break
		}
	}
	if i == valLen {
		stream.buf = append(stream.buf, '"')
		return
	}
	writeStringSlowPathWithHTMLEscaped(stream, i, s, valLen)
}
212651
func escapeText(w io.Writer, s []byte, escapeNewline bool) error {
	var esc []byte
	last := 0
	for i := 0; i < len(s); {
		r, width := utf8.DecodeRune(s[i:])
		i += width
		switch r {
		case '"':
			esc = esc_quot
		case '\'':
			esc = esc_apos
		case '&':
			esc = esc_amp
		case '<':
			esc = esc_lt
		case '>':
			esc = esc_gt
		case '\t':
			esc = esc_tab
		case '\n':
			if !escapeNewline {
				continue
			}
			esc = esc_nl
		case '\r':
			esc = esc_cr
		default:
			if !isInCharacterRange(r) || (r == 0xFFFD && width == 1) {
				esc = esc_fffd
				break
			}
			continue
		}
		if _, err := w.Write(s[last : i-width]); err != nil {
			return err
		}
		if _, err := w.Write(esc); err != nil {
			return err
		}
		last = i
	}
	if _, err := w.Write(s[last:]); err != nil {
		return err
	}
	return nil
}
590354
func (p *printer) EscapeString(s string) {
	var esc []byte
	last := 0
	for i := 0; i < len(s); {
		r, width := utf8.DecodeRuneInString(s[i:])
		i += width
		switch r {
		case '"':
			esc = escQuot
		case '\'':
			esc = escApos
		case '&':
			esc = escAmp
		case '<':
			esc = escLT
		case '>':
			esc = escGT
		case '\t':
			esc = escTab
		case '\n':
			esc = escNL
		case '\r':
			esc = escCR
		default:
			if !isInCharacterRange(r) || (r == 0xFFFD && width == 1) {
				esc = escFFFD
				break
			}
			continue
		}
		p.WriteString(s[last : i-width])
		p.Write(esc)
		last = i
	}
	p.WriteString(s[last:])
}
377854
func AppendBulkString(b []byte, bulk string) []byte {
	b = appendPrefix(b, '$', int64(len(bulk)))
	b = append(b, bulk...)
	return append(b, '\r', '\n')
}
300729
func escapeUnicode(input string) string {
	//var buffer bytes.Buffer
	buffer := bytes.NewBufferString("")
	for _, r := range input {
		if r > 65535 {
			// surrogate pair
			var r1, r2 = utf16.EncodeRune(r)
			var s = fmt.Sprintf("\\u%x\\u%x", r1, r2)
			// error always nil https://golang.org/pkg/bytes/#Buffer.WriteString
			buffer.WriteString(s) // nolint: gas, gosec
		} else if r > 127 {
			var s = fmt.Sprintf("\\u%04x", r)
			// error always nil https://golang.org/pkg/bytes/#Buffer.WriteString
			buffer.WriteString(s) // nolint: gas, gosec
		} else {
			var s = fmt.Sprintf("%c", r)
			// error always nil https://golang.org/pkg/bytes/#Buffer.WriteString
			buffer.WriteString(s) // nolint: gas, gosec
		}
	}
	return buffer.String()
}
782035
func ToString(i interface{}) string {
	if i == nil {
		return ""
	}

	if s, ok := i.(string); ok {
		return s
	}

	if sl, ok := i.([]string); ok {
		if len(sl) == 1 {
			return sl[0]
		}
	}

	return ""
}
908873
func (r *Router) TemplateGlob(pattern string) {
	r.Lock()
	defer r.Unlock()
	r.views = template.Must(template.ParseGlob(pattern))
}
12688
func escape(s string) string {
	s = strings.Replace(s, "\n", "\\n", -1)
	s = strings.Replace(s, "\"", "\\\"", -1)
	return s
}
753522
func EscapePath(path string, encodeSep bool) string {
	var buf bytes.Buffer
	for i := 0; i < len(path); i++ {
		c := path[i]
		if noEscape[c] || (c == '/' && !encodeSep) {
			buf.WriteByte(c)
		} else {
			fmt.Fprintf(&buf, "%%%02X", c)
		}
	}
	return buf.String()
}
1326268
func escapeStringQuotes(buf []byte, v string) []byte {
	pos := len(buf)
	buf = reserveBuffer(buf, len(v)*2)

	for i := 0; i < len(v); i++ {
		c := v[i]
		if c == '\'' {
			buf[pos] = '\''
			buf[pos+1] = '\''
			pos += 2
		} else {
			buf[pos] = c
			pos++
		}
	}

	return buf[:pos]
}
200945
func unescapeStringField(in string) string {
	if strings.IndexByte(in, '\\') == -1 {
		return in
	}

	var out []byte
	i := 0
	for {
		if i >= len(in) {
			break
		}
		// unescape backslashes
		if in[i] == '\\' && i+1 < len(in) && in[i+1] == '\\' {
			out = append(out, '\\')
			i += 2
			continue
		}
		// unescape double-quotes
		if in[i] == '\\' && i+1 < len(in) && in[i+1] == '"' {
			out = append(out, '"')
			i += 2
			continue
		}
		out = append(out, in[i])
		i++

	}
	return string(out)
}
572155
func hasGlob(fragment string) bool {
	match, _ := regexp.MatchString(`([^\\]|^)[[*?]`, fragment)
	return match
}
5044
func lexString(lx *lexer) stateFn {
	r := lx.next()
	//u.Infof("lexString  r = %v", string(r))
	switch {
	case r == '\\':
		return lexStringEscape
	// Termination of non-quoted strings
	case lx.isEnd(lx, r):
		lx.backup()
		if lx.isBool() {
			lx.emit(itemBool)
		} else {
			lx.emit(itemString)
		}
		return lx.pop()
	case r == sqStringEnd:
		lx.backup()
		lx.emit(itemString)
		lx.next()
		lx.ignore()
		return lx.pop()
	}
	return lexString
}
214030
func escape(dirty string) string {
	var fieldEscaper = strings.NewReplacer(
		`%`, "pct_",
		`/`, "_per_",
	)
	return fieldEscaper.Replace(dirty)
}