// custom-fitted version of strconv.Parse(Ui|I)nt.
// Also ensures we don't have to search for .eE to determine if a float or not.
// Note: s CANNOT be a zero-length slice.
181668
func jsonParseInteger(s []byte) (n uint64, neg, badSyntax, overflow bool) {
	const maxUint64 = (1<<64 - 1)
	const cutoff = maxUint64/10 + 1

	if len(s) == 0 { // bounds-check-elimination
		// treat empty string as zero value
		// badSyntax = true
		return
	}
	switch s[0] {
	case '+':
		s = s[1:]
	case '-':
		s = s[1:]
		neg = true
	}
	for _, c := range s {
		if c < '0' || c > '9' {
			badSyntax = true
			return
		}
		// unsigned integers don't overflow well on multiplication, so check cutoff here
		// e.g. (maxUint64-5)*10 doesn't overflow well ...
		if n >= cutoff {
			overflow = true
			return
		}
		n *= 10
		n1 := n + uint64(c-'0')
		if n1 < n || n1 > maxUint64 {
			overflow = true
			return
		}
		n = n1
	}
	return
}
51448
func (b *unboundBuilder) Parse(s string) (*Literal, error) {
	raw := strings.TrimSpace(s)
	if len(raw) == 0 {
		return nil, fmt.Errorf("literal.Parse: cannot parse and empty string into a literal; provided string %q", s)
	}
	if raw[0] != '"' {
		return nil, fmt.Errorf("literal.Parse: text encoded literals must start with \", missing in %s", raw)
	}
	idx := strings.Index(raw, "\"^^type:")
	if idx < 0 {
		return nil, fmt.Errorf("literal.Parse: text encoded literals must have a type; missing in %s", raw)
	}
	v := raw[1:idx]
	t := raw[idx+len("\"^^type:"):]
	switch t {
	case "bool":
		pv, err := strconv.ParseBool(v)
		if err != nil {
			return nil, fmt.Errorf("literal.Parse: could not convert value %q to bool", v)
		}
		return b.Build(Bool, pv)
	case "int64":
		pv, err := strconv.ParseInt(v, 10, 64)
		if err != nil {
			return nil, fmt.Errorf("literal.Parse: could not convert value %q to int64", v)
		}
		return b.Build(Int64, int64(pv))
	case "float64":
		pv, err := strconv.ParseFloat(v, 64)
		if err != nil {
			return nil, fmt.Errorf("literal.Parse: could not convert value %q to float64", v)
		}
		return b.Build(Float64, float64(pv))
	case "text":
		return b.Build(Text, v)
	case "blob":
		values := v[1 : len(v)-1]
		if values == "" {
			return b.Build(Blob, []byte{})
		}
		bs := []byte{}
		for _, s := range strings.Split(values, " ") {
			b, err := strconv.ParseUint(s, 10, 8)
			if err != nil {
				return nil, fmt.Errorf("literal.Parse: failed to decode byte array on %q with error %v", s, err)
			}
			bs = append(bs, byte(b))
		}
		return b.Build(Blob, bs)
	default:
		return nil, nil
	}
}
52530
func (*Bytes) Parse(value string) (i uint64, err error) {
	parts := pattern.FindStringSubmatch(value)
	if len(parts) < 3 {
		return 0, fmt.Errorf("error parsing value=%s", value)
	}
	bytesString := parts[1]
	multiple := parts[2]
	bytes, err := strconv.ParseUint(bytesString, 10, 64)
	if err != nil {
		return
	}

	switch multiple {
	case "B":
		return bytes * B, nil
	case "K", "KB":
		return bytes * KB, nil
	case "M", "MB":
		return bytes * MB, nil
	case "G", "GB":
		return bytes * GB, nil
	case "T", "TB":
		return bytes * TB, nil
	case "P", "PB":
		return bytes * PB, nil
	}

	return
}
245797
func (enc *Encoder) Float32(v float32) {
	r := enc.getPreviousRune()
	if r != '[' {
		enc.writeByte(',')
	}
	enc.buf = strconv.AppendFloat(enc.buf, float64(v), 'f', -1, 32)
}
848896
func F(n float64, v uint64) (f int64) {

	s := strconv.FormatFloat(n-float64(int64(n)), 'f', int(v), 64)

	// with either be '0' or '0.xxxx', so if 1 then f will be zero
	// otherwise need to parse
	if len(s) != 1 {

		// ignoring error, because it can't fail as we generated
		// the string internally from a real number
		f, _ = strconv.ParseInt(s[2:], 10, 64)
	}

	return
}
606142
func (e *Env) Parse() error {
	for _, name := range e.FieldNames() {
		field, _ := e.Value.Type().FieldByName(name)
		v, err := NewVar(field)

		if err != nil {
			return err
		}
		e.Value.FieldByName(name).Set(v.Value)
		e.Vars = append(e.Vars, v)
	}

	return nil
}
295595
func StringToFloat32(from string) (float32, error) {
	val, err := strconv.ParseFloat(from, 32)
	return float32(val), err
}
99580
func Parse(s string) (KSUID, error) {
	if len(s) != stringEncodedLength {
		return Nil, errStrSize
	}

	src := [stringEncodedLength]byte{}
	dst := [byteLength]byte{}

	copy(src[:], s[:])

	if err := fastDecodeBase62(dst[:], src[:]); err != nil {
		return Nil, errStrValue
	}

	return FromBytes(dst[:])
}
536133
func (parser FloatTypeParser) Parse(d DataType) error {
	if value, ok := AsFloat(d); ok {
		parser.setter(value)
	} else {
		return fmt.Errorf("Error parsing type of %#v as a Float", d)
	}
	return nil
}
772505
func parseCompExp(r string, pos int) (*vrange, int, error) {
	i := pos
	v := &vrange{}

	const (
		ce_start = iota
		val_start
		val_in
		val_end
		ce_end
	)
	st := ce_start
	vstart := 0
	vend := 0

	lt := true

LOOP:
	for ; i < len(r); i++ {
		c := r[i]
		switch c {
		case '<', '>':
			if st != ce_start {
				return nil, i, fmt.Errorf("rule parse error at position %d of rule %s", i, r)
			}
			if c == '<' {
				lt = true
			} else {
				lt = false
			}

			vstart = i + 1
			st = val_start
		case '=':
			if st != val_start {
				return nil, i, fmt.Errorf("rule parse error at position %d of rule %s, '=' should comes after '>' or '<'", i, r)
			}
			if lt {
				v.right = true
			} else {
				v.left = true
			}
			vstart += 1
		case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '.', //positive, negative, or float digital
			'A', 'B', 'C', 'D', 'E', 'F', 'a', 'b', 'c', 'd', 'e', 'f', 'X', 'x', //hex
			'h', 'm', 's', 'n', 'u', 'µ': //time.Duration
			if st == val_start {
				st = val_in
			}
		case ' ', '\t':
			switch st {
			case val_start:
				vstart = i + 1
			case val_in:
				st = val_end
				vend = i
				val := r[vstart:vend]
				num, err := parseInt(val)
				if err != nil {
					return nil, i, err
				}
				if lt {
					v.max = num
				} else {
					v.min = num
				}
				st = ce_end
				break LOOP
			default:
			}
		default:
			return nil, i, fmt.Errorf("unknown char at position %d of rule %s", i, r)
		}
	}
	if i == len(r) && st == val_in {
		st = val_end
		vend = i
		val := r[vstart:vend]
		num, err := parseInt(val)
		if err != nil {
			return nil, i, err
		}
		if lt {
			v.max = num
		} else {
			v.min = num
		}
		st = ce_end

	}
	if st != ce_end {
		return nil, i, fmt.Errorf("rule is incompleted %s", r)
	}

	if lt {
		v.min = math.MinInt64
	} else {
		v.max = math.MaxInt64
	}
	return v, i, nil
}
352625
func parse_number(data []rune, p int, pe int) (Value, int, error) {
	var (
		cs int
		eof = pe
		ret Value
		start = p
	)
	_ = eof

//line ucl.go:100
	{
	cs = number_start
	}

//line ucl.rl:72

//line ucl.go:107
	{
	var _klen int
	var _trans int
	var _acts int
	var _nacts uint
	var _keys int
	if p == pe {
		goto _test_eof
	}
	if cs == 0 {
		goto _out
	}
_resume:
	_keys = int(_number_key_offsets[cs])
	_trans = int(_number_index_offsets[cs])

	_klen = int(_number_single_lengths[cs])
	if _klen > 0 {
		_lower := int(_keys)
		var _mid int
		_upper := int(_keys + _klen - 1)
		for {
			if _upper < _lower {
				break
			}

			_mid = _lower + ((_upper - _lower) >> 1)
			switch {
			case data[p] < _number_trans_keys[_mid]:
				_upper = _mid - 1
			case data[p] > _number_trans_keys[_mid]:
				_lower = _mid + 1
			default:
				_trans += int(_mid - int(_keys))
				goto _match
			}
		}
		_keys += _klen
		_trans += _klen
	}

	_klen = int(_number_range_lengths[cs])
	if _klen > 0 {
		_lower := int(_keys)
		var _mid int
		_upper := int(_keys + (_klen << 1) - 2)
		for {
			if _upper < _lower {
				break
			}

			_mid = _lower + (((_upper - _lower) >> 1) & ^1)
			switch {
			case data[p] < _number_trans_keys[_mid]:
				_upper = _mid - 2
			case data[p] > _number_trans_keys[_mid + 1]:
				_lower = _mid + 2
			default:
				_trans += int((_mid - int(_keys)) >> 1)
				goto _match
			}
		}
		_trans += _klen
	}

_match:
	_trans = int(_number_indicies[_trans])
	cs = int(_number_trans_targs[_trans])

	if _number_trans_actions[_trans] == 0 {
		goto _again
	}

	_acts = int(_number_trans_actions[_trans])
	_nacts = uint(_number_actions[_acts]); _acts++
	for ; _nacts > 0; _nacts-- {
		_acts++
		switch _number_actions[_acts-1] {
		case 0:
//line ucl.rl:27
 p--
 p++; goto _out
 
		case 1:
//line ucl.rl:41

		if strings.IndexAny(string(data[start:p]), ".eE") >= 0 {
			v, err := strconv.ParseFloat(string(data[start:p]), 64)
			if err != nil {
				return nil, -1, err
			}
			ret = &Number{Value: v}
		} else {
			v, err := strconv.ParseInt(string(data[start:p]), 10, 64)
			if err != nil {
				return nil, -1, err
			}
			ret = &Integer{Value: v}
		}
	
//line ucl.go:208
		}
	}

_again:
	if cs == 0 {
		goto _out
	}
	p++
	if p != pe {
		goto _resume
	}
	_test_eof: {}
	_out: {}
	}

//line ucl.rl:73

	if cs >= number_first_final {
		return ret, p, nil
	}
	return nil, -1, parserError{machine: "number", offset: p, state: cs}
}
473301
func Parse(filePath string, objName string) (*ParsedPkg, error) {
	fs := token.NewFileSet()
	pkg, err := parser.ParseFile(fs, filePath, nil, parser.AllErrors)
	if err != nil {
		return nil, err
	}
	p := &ParsedPkg{}
	p.Name = pkg.Name.Name
	obj, exists := pkg.Scope.Objects[objName]
	if !exists {
		return nil, fmt.Errorf("could not find object %s in %s", objName, filePath)
	}
	if obj.Kind != ast.Typ {
		return nil, fmt.Errorf("exected type, got %s", obj.Kind)
	}
	spec, ok := obj.Decl.(*ast.TypeSpec)
	if !ok {
		return nil, errUnexpectedType{"*ast.TypeSpec", obj.Decl}
	}
	iface, ok := spec.Type.(*ast.InterfaceType)
	if !ok {
		return nil, errUnexpectedType{"*ast.InterfaceType", spec.Type}
	}

	p.Functions, err = parseInterface(iface)
	if err != nil {
		return nil, err
	}

	// figure out what imports will be needed
	imports := make(map[string]importSpec)
	for _, f := range p.Functions {
		args := append(f.Args, f.Returns...)
		for _, arg := range args {
			if len(arg.PackageSelector) == 0 {
				continue
			}

			for _, i := range pkg.Imports {
				if i.Name != nil {
					if i.Name.Name != arg.PackageSelector {
						continue
					}
					imports[i.Path.Value] = importSpec{Name: arg.PackageSelector, Path: i.Path.Value}
					break
				}

				_, name := path.Split(i.Path.Value)
				splitName := strings.Split(name, "-")
				if len(splitName) > 1 {
					name = splitName[len(splitName)-1]
				}
				// import paths have quotes already added in, so need to remove them for name comparison
				name = strings.TrimPrefix(name, `"`)
				name = strings.TrimSuffix(name, `"`)
				if name == arg.PackageSelector {
					imports[i.Path.Value] = importSpec{Path: i.Path.Value}
					break
				}
			}
		}
	}

	for _, spec := range imports {
		p.Imports = append(p.Imports, spec)
	}

	return p, nil
}
618309
func ParseRect(s string) (r Rect, err error) {
	_, err = fmt.Sscan(s, &r.Min[0], &r.Min[1], &r.Max[0], &r.Max[1])
	return r, err
}
952866
func getCommaSeparatedStringEnvVar(envVar string, def []string) []string {
	if val := os.Getenv(envVar); val != "" {
		def = def[:0]
		for _, addr := range strings.Split(strings.Replace(val, " ", "", -1), ",") {
			def = append(def, addr)
		}
	}
	return def
}
1247847
func (c *IniConfigContainer) Float(key string) (float64, error) {
	return strconv.ParseFloat(c.getdata(key), 64)
}
945203
func parseSizeInBytes(sizeStr string) uint {
	sizeStr = strings.TrimSpace(sizeStr)
	lastChar := len(sizeStr) - 1
	multiplier := uint(1)

	if lastChar > 0 {
		if sizeStr[lastChar] == 'b' || sizeStr[lastChar] == 'B' {
			if lastChar > 1 {
				switch unicode.ToLower(rune(sizeStr[lastChar-1])) {
				case 'k':
					multiplier = 1 << 10
					sizeStr = strings.TrimSpace(sizeStr[:lastChar-1])
				case 'm':
					multiplier = 1 << 20
					sizeStr = strings.TrimSpace(sizeStr[:lastChar-1])
				case 'g':
					multiplier = 1 << 30
					sizeStr = strings.TrimSpace(sizeStr[:lastChar-1])
				default:
					multiplier = 1
					sizeStr = strings.TrimSpace(sizeStr[:lastChar])
				}
			}
		}
	}

	size := cast.ToInt(sizeStr)
	if size < 0 {
		size = 0
	}

	return safeMul(uint(size), multiplier)
}
624174
func Parse(content string, spec *vpython.Spec) error {
	if err := cproto.UnmarshalTextML(content, spec); err != nil {
		return errors.Annotate(err, "failed to unmarshal vpython.Spec").Err()
	}
	return nil
}