// StderrMatches compares a regex to the stderr produced by the command.
431151
func (c *Cmd) StderrMatches(regex string) bool {
	c.validate()
	re := regexp.MustCompile(regex)
	return re.MatchString(c.Stderr())
}
729021
func losetup(args ...string) (string, error) {
	data, err := exec.Command("losetup", args...).CombinedOutput()
	output := string(data)
	if err != nil {
		return "", errors.Wrapf(err, "losetup %s\nerror: %s\n", strings.Join(args, " "), output)
	}

	return strings.TrimSuffix(output, "\n"), err
}
67933
func (c *Conn) MatchPrefix(key string, maxrecords int64) ([]string, error) {
	keystransmit := []KV{
		{"prefix", []byte(key)},
		{"max", []byte(strconv.FormatInt(maxrecords, 10))},
	}
	code, m, err := c.doRPC("/rpc/match_prefix", keystransmit)
	if err != nil {
		return nil, err
	}
	if code != 200 {
		return nil, makeError(m)
	}
	res := make([]string, 0, len(m))
	for _, kv := range m {
		if kv.Key[0] == '_' {
			res = append(res, string(kv.Key[1:]))
		}
	}
	if len(res) == 0 {
		// yeah, gokabinet was weird here.
		return nil, ErrSuccess
	}
	return res, nil
}
414690
func decodeRune(s string) rune {
	if strings.HasPrefix(s, "0x") {
		i, err := strconv.ParseInt(s, 0, 16)
		if err != nil {
			panic(err)
		}
		return rune(i)
	}

	if !strings.HasPrefix(s, "'") || !strings.HasSuffix(s, "'") {
		panic(fmt.Sprintf("expected character, got: %s", s))
	}

	if len(s) == 4 {
		if s[1] != '\\' {
			panic(fmt.Sprintf("expected escaped character, got: %s", s))
		}
		return rune(s[2])
	}

	if len(s) != 3 {
		panic(fmt.Sprintf("expected character, got: %s", s))
	}

	return rune(s[1])
}
53657
func DisallowedURLFilters(filters ...*regexp.Regexp) func(*Collector) {
	return func(c *Collector) {
		c.DisallowedURLFilters = filters
	}
}
311135
func (rc MultiRegexCommand) getRegexMatch(text string) (bool, *regexp.Regexp) {
	for _, r := range rc.Regex {
		if r.MatchString(text) {
			return true, r
		}
	}
	return false, nil
}
462917
func AddStderr(name, stdout, stderr string) (string, error) {
	return add(name, stdout, stderr, 0)
}
1092254
func (p *parserMixin) Regexp() (target **regexp.Regexp) {
	target = new(*regexp.Regexp)
	p.RegexpVar(target)
	return
}
152980
func (a *Assertions) Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool {
	return Regexp(a.t, rx, str, msgAndArgs...)
}
1253656
func (a *Assertions) Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool {
	if h, ok := a.t.(tHelper); ok {
		h.Helper()
	}
	return Regexp(a.t, rx, str, msgAndArgs...)
}
835519
func stripGrpcPrefixArgs(args ...interface{}) []interface{} {
	if len(args) == 0 {
		return args
	}
	firstArgStr, ok := args[0].(string)
	if ok {
		args[0] = stripGrpcPrefix(firstArgStr)
	}
	return args
}
857193
func getRegEx(pattern string) *regexp.Regexp {
	for _, trs := range []struct {
		old, new string
	}{
		{".", `\.`}, // Escape all '.' in the pattern
		{"(", `\(`}, // Escape all '(' in the pattern
		{")", `\)`}, // Escape all ')' in the pattern
		{"*", ".*"}, // Replace a '*' with '.*' that matches zero or more chars
		{"{", "("},  // Change a '{' to '('
		{",", "|"},  // Change a ',' to '|'
		{"}", ")"},  // Change a '}' to ')'
		{"?", "."},  // Change a '?' to '.'
	} {
		pattern = strings.Replace(pattern, trs.old, trs.new, -1)
	}

	return regexp.MustCompile(pattern)
}
806043
func (ld *LineDelimiter) Flush() (err error) {
	lines := strings.Split(ld.buf.String(), "\n")
	for _, line := range lines {
		if _, err = ld.output.Write(ld.delimiter); err != nil {
			return
		}
		if _, err = ld.output.Write([]byte(line)); err != nil {
			return
		}
		if _, err = ld.output.Write(ld.delimiter); err != nil {
			return
		}
		if _, err = ld.output.Write([]byte("\n")); err != nil {
			return
		}
	}
	return
}
517739
func Regexp(message string, reg *regexp.Regexp, defaultAnswer string) string {
	return (&Prompter{
		Message: message,
		Regexp:  reg,
		Default: defaultAnswer,
	}).Prompt()
}
673244
func CompileStrs(regStrs []string) (*regexp.Regexp, error) {
	if len(regStrs) == 0 {
		return nil, fmt.Errorf("regStrs must be greater than or equal to 1")
	}
	regStr := "(" + strings.Join(regStrs, "|") + ")"
	re, err := regexp.Compile(regStr)
	if err != nil {
		return nil, err
	}
	return re, nil
}
1361862
func Scrub(str, repl string) string {
	var buf *bytes.Buffer
	var r rune
	var size, pos int
	var hasError bool

	origin := str

	for len(str) > 0 {
		r, size = utf8.DecodeRuneInString(str)

		if r == utf8.RuneError {
			if !hasError {
				if buf == nil {
					buf = &bytes.Buffer{}
				}

				buf.WriteString(origin[:pos])
				hasError = true
			}
		} else if hasError {
			hasError = false
			buf.WriteString(repl)

			origin = origin[pos:]
			pos = 0
		}

		pos += size
		str = str[size:]
	}

	if buf != nil {
		buf.WriteString(origin)
		return buf.String()
	}

	// No invalid byte.
	return origin
}
178347
func replaceBadChars(s string) string {
	// strip bad characters
	r := []rune{}
	for _, ch := range s {
		if isIdentifierChar(ch) {
			r = append(r, ch)
		} else {
			r = append(r, '_')
		}
	}

	return string(r)
}