// parseDfOutput attempts to parse output from a df call.  It supports multiple
// options for block sizes.  Returns a dfStats object for each mounted device
// in the df ouput
436383
func parseDfOutput(r io.Reader) ([]*dfStats, error) {
	getBytes := func(blockStr string) (uint64, error) {
		base := uint64(1024)
		bytes := uint64(0)
		b := uint64(0)
		var err error
		// in df output, kB, MB, etc are powers of 1000, K, M, etc are powers of 1024
		if strings.HasSuffix(blockStr, "B") {
			base = 1000
		}
		blockStr = strings.TrimSuffix(blockStr, "B")
		if strings.HasSuffix(blockStr, "K") {
			b, err = strconv.ParseUint(strings.TrimSuffix(blockStr, "K"), 10, 64)
			bytes = b * base
		} else if strings.HasSuffix(blockStr, "M") {
			b, err = strconv.ParseUint(strings.TrimSuffix(blockStr, "M"), 10, 64)
			bytes = b * base * base
		} else if strings.HasSuffix(blockStr, "G") {
			b, err = strconv.ParseUint(strings.TrimSuffix(blockStr, "G"), 10, 64)
			bytes = b * base * base * base
		} else if strings.HasSuffix(blockStr, "T") {
			b, err = strconv.ParseUint(strings.TrimSuffix(blockStr, "T"), 10, 64)
			bytes = b * base * base * base * base
		} else {
			bytes, err = strconv.ParseUint(blockStr, 10, 64)
		}

		return bytes, err
	}
	scanner := bufio.NewScanner(r)
	statsSlice := make([]*dfStats, 0, 3)
	var err error
	var blockSize uint64
	for scanner.Scan() {
		line := scanner.Text()
		f := strings.Fields(line)
		// Read block size from output header
		if strings.HasPrefix(f[0], "Filesystem") {
			blockSizeStr := strings.Split(f[1], "-")[0]
			blockSize, err = getBytes(blockSizeStr)
			if err != nil {
				return statsSlice, err
			}
		} else {
			filesystemPath := f[0]
			totalBlocks, err := strconv.ParseUint(f[1], 10, 64)
			if err != nil {
				return statsSlice, err
			}
			usedBlocks, err := strconv.ParseUint(f[2], 10, 64)
			if err != nil {
				return statsSlice, err
			}
			availableBlocks, err := strconv.ParseUint(f[3], 10, 64)
			if err != nil {
				return statsSlice, err
			}
			mountPoint := f[5]
			statsSlice = append(statsSlice, &dfStats{
				BlockSize:       blockSize,
				FilesystemPath:  filesystemPath,
				BlocksTotal:     totalBlocks,
				BlocksUsed:      usedBlocks,
				BlocksAvailable: availableBlocks,
				MountPoint:      mountPoint,
			})
		}
	}
	return statsSlice, nil
}
749603
func ParseDataSet(s string) (string, []*Type, error) {
	splitFn := func(c rune) bool {
		return c == '\t' || c == ' ' || c == ','
	}
	fields := strings.FieldsFunc(s, splitFn)

	if len(fields) < 2 {
		return "", nil, fmt.Errorf("Minimum of 2 fields required \"%s\"", s)
	}

	dataSetName := fields[0]
	dataSetSources := make([]*Type, len(fields[1:]))

	// Parse each data source
	for i, field := range fields[1:] {
		// Split data source fields
		dsFields := strings.Split(field, ":")
		if len(dsFields) != 4 {
			return "", nil, fmt.Errorf("Exactly 4 fields required \"%s\"", field)
		}

		// Parse data source type
		dsTypeStr := strings.ToLower(dsFields[1])
		dsType, ok := ValueTypeNames[dsTypeStr]
		if !ok {
			return "", nil, fmt.Errorf("Invalid data-source type \"%s\"", dsTypeStr)
		}

		dataSetSources[i] = &Type{
			Name: dsFields[0],
			Type: dsType,
			Min:  dsFields[2],
			Max:  dsFields[3],
		}
	}

	return dataSetName, dataSetSources, nil
}
837855
func ParseDuration(s string) (d time.Duration, err error) {
	r := strings.NewReader(s)

	switch {
	case strings.HasSuffix(s, "d"):
		var v float64
		_, err = fmt.Fscanf(r, "%fd", &v)
		d = time.Duration(v * float64(24*time.Hour))
	case strings.HasSuffix(s, "w"):
		var v float64
		_, err = fmt.Fscanf(r, "%fw", &v)
		d = time.Duration(v * float64(24*time.Hour*7))
	case strings.HasSuffix(s, "mo"):
		var v float64
		_, err = fmt.Fscanf(r, "%fmo", &v)
		d = time.Duration(v * float64(30*24*time.Hour))
	case strings.HasSuffix(s, "M"):
		var v float64
		_, err = fmt.Fscanf(r, "%fM", &v)
		d = time.Duration(v * float64(30*24*time.Hour))
	default:
		d, err = time.ParseDuration(s)
	}

	return
}
102955
func (fs *FileSorter) Output() ([]types.Datum, []types.Datum, int64, error) {
	if fs.closed {
		return nil, nil, 0, errors.New("FileSorter has been closed")
	}
	if len(fs.files) == 0 {
		// No external files generated.
		// Perform full in-memory sort directly.
		r, err := fs.internalSort()
		if err != nil {
			return nil, nil, 0, errors.Trace(err)
		} else if r != nil {
			return r.key, r.val, r.handle, nil
		} else {
			return nil, nil, 0, nil
		}
	}
	r, err := fs.externalSort()
	if err != nil {
		return nil, nil, 0, errors.Trace(err)
	} else if r != nil {
		return r.key, r.val, r.handle, nil
	} else {
		return nil, nil, 0, nil
	}
}
1229792
func (p *parser) parseFuncTypeOrLit() ast.Expr {
	if p.trace {
		defer un(trace(p, "FuncTypeOrLit"))
	}

	typ, scope := p.parseFuncType()
	if p.tok != token.LBRACE {
		// function type only
		return typ
	}

	p.exprLev++
	body := p.parseBody(scope)
	p.exprLev--

	return &ast.FuncLit{typ, body}
}
957000
func ParseDistanceUnit(u string) (float64, error) {
	for _, unit := range distanceUnits {
		for _, unitSuffix := range unit.suffixes {
			if u == unitSuffix {
				return unit.conv, nil
			}
		}
	}
	return 0, fmt.Errorf("unknown distance unit: %s", u)
}
764079
func (d *Dataset) Output(f func(io.Reader) error) *Dataset {
	step := d.Flow.AddAllToOneStep(d, nil)
	step.IsOnDriverSide = true
	step.Name = "Output"
	step.Function = func(readers []io.Reader, writers []io.Writer, stat *pb.InstructionStat) error {
		errChan := make(chan error, len(readers))
		for i, reader := range readers {
			go func(i int, reader io.Reader) {
				errChan <- f(reader)
			}(i, reader)
		}
		for range readers {
			err := <-errChan
			if err != nil {
				fmt.Fprintf(os.Stderr, "Failed to process output: %v\n", err)
				return err
			}
		}
		return nil
	}
	return d
}
146655
func parseDuration(input string) (time.Duration, error) {
	d, err := time.ParseDuration(input)
	if err != nil {
		n, err := strconv.ParseFloat(input, 64)
		if err != nil {
			return 0, err
		}
		d = time.Duration(n*1000) * time.Millisecond
	}
	return d, nil
}
906630
func ioOutputFormatFunction(ld *LineData, b *bytes.Buffer) error {
	_, err := b.WriteString(ld.CallingFunction)
	return err
}
757606
func (f *framer) parseSupportedFrame() frame {
	return &supportedFrame{
		frameHeader: *f.header,

		supported: f.readStringMultiMap(),
	}
}
632354
func (p *parser) parseBuiltinFunc() (*Decl, error) {
	var d *Decl
	var err error

	// COUNT(attribute)
	if p.is(CountToken) {
		d, err = p.consumeToken(CountToken)
		if err != nil {
			return nil, err
		}
		// Bracket
		_, err = p.consumeToken(BracketOpeningToken)
		if err != nil {
			return nil, err
		}
		// Attribute
		attr, err := p.parseAttribute()
		if err != nil {
			return nil, err
		}
		d.Add(attr)
		// Bracket
		_, err = p.consumeToken(BracketClosingToken)
		if err != nil {
			return nil, err
		}
	}

	return d, nil
}
485839
func (ini *INI) ParseFrom(r io.Reader, lineSep, kvSep string) error {
    data, err := ioutil.ReadAll(r)
    if err == nil {
        return ini.parseINI(data, lineSep, kvSep)
    }
    return err
}
1077543
func (r ClientRequest) RawPut(path string, payload []byte, f func(*http.Request)) ([]byte, *http.Response, error) {
	url := fmt.Sprintf("%s%s", r.endpoint, path)

	wrapperFunc := r.setContextIDHeader(f)

	resp, err := r.httpClient.PutCustomized(url, payload, wrapperFunc)
	if err != nil {
		return nil, nil, bosherr.WrapErrorf(err, "Performing request PUT '%s'", url)
	}

	return r.optionallyFollowResponse(url, resp)
}
305836
func getParseFunc(log []byte) (parseFunc, error) {
	for _, p := range parseFuncs {
		if err := p(log, &logMessage{}); err == nil {
			return p, nil
		}
	}
	return nil, fmt.Errorf("unsupported log format: %q", log)
}
368182
func ParseDuration(str string, fsp int) (Duration, error) {
	var (
		day    int
		hour   int
		minute int
		second int
		frac   int

		err       error
		sign      = 0
		dayExists = false
	)

	fsp, err = checkFsp(fsp)
	if err != nil {
		return ZeroDuration, errors.Trace(err)
	}

	if len(str) == 0 {
		return ZeroDuration, nil
	} else if str[0] == '-' {
		str = str[1:]
		sign = -1
	}

	// Time format may has day.
	if n := strings.IndexByte(str, ' '); n >= 0 {
		if day, err = strconv.Atoi(str[:n]); err == nil {
			dayExists = true
		}
		str = str[n+1:]
	}

	var overflow bool
	if n := strings.IndexByte(str, '.'); n >= 0 {
		// It has fractional precesion parts.
		fracStr := str[n+1:]
		frac, overflow, err = parseFrac(fracStr, fsp)
		if err != nil {
			return ZeroDuration, errors.Trace(err)
		}
		str = str[0:n]
	}

	// It tries to split str with delimiter, time delimiter must be :
	seps := strings.Split(str, ":")

	switch len(seps) {
	case 1:
		if dayExists {
			hour, err = strconv.Atoi(seps[0])
		} else {
			// No delimiter.
			if len(str) == 6 {
				// HHMMSS
				_, err = fmt.Sscanf(str, "%2d%2d%2d", &hour, &minute, &second)
			} else if len(str) == 4 {
				// MMSS
				_, err = fmt.Sscanf(str, "%2d%2d", &minute, &second)
			} else if len(str) == 2 {
				// SS
				_, err = fmt.Sscanf(str, "%2d", &second)
			} else {
				// Maybe only contains date.
				_, err = ParseDate(str)
				if err == nil {
					return ZeroDuration, nil
				}
				return ZeroDuration, errors.Trace(ErrInvalidTimeFormat)
			}
		}
	case 2:
		// HH:MM
		_, err = fmt.Sscanf(str, "%2d:%2d", &hour, &minute)
	case 3:
		// Time format maybe HH:MM:SS or HHH:MM:SS.
		// See https://dev.mysql.com/doc/refman/5.7/en/time.html
		if !dayExists && len(seps[0]) == 3 {
			_, err = fmt.Sscanf(str, "%3d:%2d:%2d", &hour, &minute, &second)
		} else {
			_, err = fmt.Sscanf(str, "%2d:%2d:%2d", &hour, &minute, &second)
		}
	default:
		return ZeroDuration, errors.Trace(ErrInvalidTimeFormat)
	}

	if err != nil {
		return ZeroDuration, errors.Trace(err)
	}

	if overflow {
		second++
		frac = 0
	}
	d := gotime.Duration(day*24*3600+hour*3600+minute*60+second)*gotime.Second + gotime.Duration(frac)*gotime.Microsecond
	if sign == -1 {
		d = -d
	}

	if d > MaxTime {
		d = MaxTime
		err = ErrInvalidTimeFormat
	} else if d < MinTime {
		d = MinTime
		err = ErrInvalidTimeFormat
	}
	return Duration{Duration: d, Fsp: fsp}, errors.Trace(err)
}
735794
func columnOutput(list []string, c *columnize.Config) string {
	if len(list) == 0 {
		return ""
	}

	if c == nil {
		c = &columnize.Config{}
	}
	if c.Glue == "" {
		c.Glue = "    "
	}
	if c.Empty == "" {
		c.Empty = "n/a"
	}

	return columnize.Format(list, c)
}
71032
func parseFieldDataLength(data []byte) (uint16, error) {
	if len(data) != 2 {
		return 0, fmt.Errorf("data length must be 2 bytes, was %d",
			len(data))
	}

	return uint16(data[0])<<5 | uint16(data[1]), nil
}