// Called when processing a code string and another '%' is found in the format
// string.
186189
func (fp *formatParser) codeCode(i int, r rune) error {
	fp.processCode(i)
	fp.start = i
	fp.code = (*formatParser).freshCode
	fp.next = (*formatParser).freshNext
	fp.end = (*formatParser).freshEnd
	return nil
}
1206181
func (exp *KeyValueExpr) String() string {
	return fmt.Sprintf("%s: %s", exp.Key, exp.Value)
}
1051475
func (c *Compiler) CompileString() (string, error) {
	var buf bytes.Buffer

	if err := c.CompileWriter(&buf); err != nil {
		return "", err
	}

	result := buf.String()

	return result, nil
}
43063
func (f *formatter) formatString(b []byte, s string) {
	if len(s) > len(b) {
		f.err = ErrFieldTooLong
	}
	copy(b, s)
	if len(s) < len(b) {
		b[len(s)] = 0
	}

	// Some buggy readers treat regular files with a trailing slash
	// in the V7 path field as a directory even though the full path
	// recorded elsewhere (e.g., via PAX record) contains no trailing slash.
	if len(s) > len(b) && b[len(b)-1] == '/' {
		n := len(strings.TrimRight(s[:len(b)], "/"))
		b[n] = 0 // Replace trailing slash with NUL terminator
	}
}
921641
func MustCompile(str string, opt RegexOptions) *Regexp {
	regexp, error := Compile(str, opt)
	if error != nil {
		panic(`regexp2: Compile(` + quote(str) + `): ` + error.Error())
	}
	return regexp
}
951954
func (f RegexFormatChecker) IsFormat(input interface{}) bool {
	asString, ok := input.(string)
	if !ok {
		return false
	}

	if asString == "" {
		return true
	}
	_, err := regexp.Compile(asString)
	return err == nil
}
162365
func formatAsString(v reflect.Value, kind reflect.Kind) string {
	if kind == reflect.Ptr && !v.IsNil() {
		v = v.Elem()
	}

	return fmt.Sprintf("%v", v.Interface())
}
627607
func (fp *formatParser) processCode(index int) error {
	code := fp.format[fp.start+1 : index]
	switch {
	case code == "":
		fp.addStatic([]byte("%"))

		// LineData strings.
	case code == "class":
		fp.addFormatFunc(ioOutputFormatClass, 6)
	case code == "classfixed":
		fp.addFormatFunc(ioOutputFormatClassFixed, 5)
	case code == "message":
		// len(ld.Message) already gets added into the buffer.
		fp.addFormatFunc(ioOutputFormatMessage, 0)

		// Time format functions.
	case code == "nanosecond":
		fp.addFormatFunc(ioOutputFormatNanoSecond, 9)
	case code == "second":
		fp.addFormatFunc(ioOutputFormatSecond, 2)
	case code == "minute":
		fp.addFormatFunc(ioOutputFormatMinute, 2)
	case code == "hour":
		fp.addFormatFunc(ioOutputFormatHour, 2)
	case code == "day":
		fp.addFormatFunc(ioOutputFormatDay, 2)
	case code == "month":
		fp.addFormatFunc(ioOutputFormatMonth, 2)
	case code == "year":
		fp.addFormatFunc(ioOutputFormatYear, 4)
	case code == "epoch":
		fp.addFormatFunc(ioOutputFormatEpoch, 10)
	case code == "tzoffset":
		fp.addFormatFunc(ioOutputFormatTZOffset, 5)
	case code == "tz":
		fp.addFormatFunc(ioOutputFormatTZ, 4)

		// System level tools.
	case code == "hostname":
		fp.addFormatFunc(ioOutputFormatHostname, 4)
	case code == "pid":
		fp.addFormatFunc(ioOutputFormatPid, 0)

		// Calling code fields.
	case code == "package":
		fp.addFormatFunc(ioOutputFormatPackage, 0)
	case code == "function":
		fp.addFormatFunc(ioOutputFormatFunction, 0)
	case code == "sourcefile":
		fp.addFormatFunc(ioOutputFormatSourceFile, 0)
	case code == "sourceline":
		fp.addFormatFunc(ioOutputFormatSourceLine, 0)
	case code == "json:message":
		fp.addFormatFunc(ioOutputFormatJsonMessage, 0)

		// Field access.
	case strings.HasPrefix(code, "field:"):
		if len(code) < 7 {
			return fmt.Errorf("Color code left empty.")
		}
		fp.addFormatFunc(ioOutputFormatField(code[6:]), 0)

		// Color:
	case strings.HasPrefix(code, "color:"):
		if len(code) < 7 {
			return fmt.Errorf("Color code left empty.")
		}
		if err := fp.setAnsiColor(code[6:]); err != nil {
			return err
		}

	default:
		// Unknown
		return fmt.Errorf("Unknown format code: %s", code)
	}
	return nil
}
419263
func (d *Decoder) string() (string, error) {
	d.pos++

	var (
		unquote bool
		start   = d.pos
	)

scan:
	for {
		if d.pos >= d.end {
			return "", ErrUnexpectedEOF
		}

		c := d.data[d.pos]
		switch {
		case c == '"':
			var s string
			if unquote {
				// stack-allocated array for allocation-free unescaping of small strings
				// if a string longer than this needs to be escaped, it will result in a
				// heap allocation; idea comes from github.com/burger/jsonparser
				var stackbuf [64]byte
				data, ok := unquoteBytes(d.data[start:d.pos], stackbuf[:])
				if !ok {
					return "", ErrStringEscape
				}
				s = string(data)
			} else {
				if d.usestring {
					s = d.sdata[start:d.pos]
				} else {

					s = string(d.data[start:d.pos])
				}
			}
			d.pos++
			return s, nil
		case c == '\\':
			d.pos++
			unquote = true
			switch c := d.data[d.pos]; c {
			case 'u':
				goto escape_u
			case 'b', 'f', 'n', 'r', 't', '\\', '/', '"':
				d.pos++
			default:
				return "", d.error(c, "in string escape code")
			}
		case c < 0x20:
			return "", d.error(c, "in string literal")
		default:
			d.pos++
			if c > unicode.MaxASCII {
				unquote = true
			}
		}
	}

escape_u:
	d.pos++
	for i := 0; i < 3; i++ {
		if d.pos < d.end {
			c := d.data[d.pos+i]
			if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' {
				continue
			}
			return "", d.error(c, "in \\u hexadecimal character escape")
		}
		return "", ErrInvalidHexEscape
	}
	d.pos += 3
	goto scan
}
1195318
func (d *Decoder) String() string {
	out := fmt.Sprintf("Format: %s - ", d.Form)
	if d.Form == aifcID {
		out += fmt.Sprintf("%s - ", d.EncodingName)
	}
	if d.SampleRate != 0 {
		out += fmt.Sprintf("%d channels @ %d / %d bits - ", d.NumChans, d.SampleRate, d.BitDepth)
		dur, _ := d.Duration()
		out += fmt.Sprintf("Duration: %f seconds\n", dur.Seconds())
	}
	return out
}
839266
func Compile(s string) (expr Expression, err error) {
	if s == "0" {
		return constValue{value: 0}, nil
	}
	if !strings.Contains(s, "?") {
		s += "?1:0"
	}
	return compileExpression(s)
}
828354
func CheckDecodeString(input string) (result []byte, err error) {
	decoded, err := DecodeString(input)
	if err != nil {
		return
	}
	if len(decoded) < 1 {
		err = ErrInvalidFormat
		return
	}
	cksum := decoded[len(decoded)-1]
	result = decoded[:len(decoded)-1]
	if checksum(result) != cksum {
		err = ErrChecksum
		return
	}
	return
}
77561
func (i ContainsExpr) String() string {
	return fmt.Sprintf("contains(%v, %v)", i.Left, i.Right)
}
1095879
func (f *SourceFile) FormatCode() error {
	// Parse file into AST
	fset := token.NewFileSet()
	file, err := parser.ParseFile(fset, f.Abs(), nil, parser.ParseComments)
	if err != nil {
		content, _ := ioutil.ReadFile(f.Abs())
		var buf bytes.Buffer
		scanner.PrintError(&buf, err)
		return fmt.Errorf("%s\n========\nContent:\n%s", buf.String(), content)
	}
	// Clean unused imports
	imports := astutil.Imports(fset, file)
	for _, group := range imports {
		for _, imp := range group {
			path := strings.Trim(imp.Path.Value, `"`)
			if !astutil.UsesImport(file, path) {
				if imp.Name != nil {
					astutil.DeleteNamedImport(fset, file, imp.Name.Name, path)
				} else {
					astutil.DeleteImport(fset, file, path)
				}
			}
		}
	}
	ast.SortImports(fset, file)
	// Open file to be written
	w, err := os.OpenFile(f.Abs(), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.ModePerm)
	if err != nil {
		return err
	}
	defer w.Close()
	// Write formatted code without unused imports
	return format.Node(w, fset, file)
}
4704
func percentToString(f float64) string {
	fInt := int64(f * 1000)
	if fInt == 0 {
		return "0"
	}
	if fInt == 1000 {
		return "100"
	}
	if fInt < 0 || fInt > 1000 {
		return "INVALID"
	}
	r := strconv.FormatInt(fInt, 10)
	r = strings.TrimRight(r, "0")
	for len(r) < 2 {
		r = r + "0"
	}
	return r
}
310255
func (a ScmpAction) String() string {
	switch a & 0xFFFF {
	case ActKill:
		return "Action: Kill Process"
	case ActTrap:
		return "Action: Send SIGSYS"
	case ActErrno:
		return fmt.Sprintf("Action: Return error code %d", (a >> 16))
	case ActTrace:
		return fmt.Sprintf("Action: Notify tracing processes with code %d",
			(a >> 16))
	case ActLog:
		return "Action: Log system call"
	case ActAllow:
		return "Action: Allow system call"
	default:
		return fmt.Sprintf("Unrecognized Action %#x", uint(a))
	}
}
295806
func (p LabelPrefix) String() string {
	s := fmt.Sprintf("%s:%s", p.Source, p.Prefix)
	if p.Ignore {
		s = "!" + s
	}

	return s
}