// parseInt parses the passed string as an int and returns it
// or 0 on errors
170203
func parseInt(str string) int {
	i := 0

	if iv, err := strconv.ParseInt(str, 10, 32); err == nil {
		i = int(iv)
	}

	return i
}
55172
func ParseIP(remoteaddr string) (string, error) {
	host, _, err := net.SplitHostPort(remoteaddr)
	if err != nil {
		return "", err
	}
	ip := net.ParseIP(host)
	if ip == nil {
		return "", errors.New("Invalid IP Address")
	}
	return ip.String(), nil
}
411388
func asInt(param string) (int64, error) {
	i, err := strconv.ParseInt(param, 0, 64)
	if err != nil {
		return 0, ErrBadParameter
	}
	return i, nil
}
962711
func (p *gc_parser) parse_number() {
	p.parse_int()
	if p.lit == "p" {
		p.next()
		p.parse_int()
	}
}
430966
func (p *gc_parser) parse_int() {
	switch p.tok {
	case '-', '+':
		p.next()
	}
	p.expect(scanner.Int)
}
355216
func ParseID(id string) (*ID, error) {
	val := uuid.Parse(id)
	if val == nil {
		return nil, trace.BadParameter("'%v' is not a valid Time UUID v1", id)
	}
	if ver, ok := val.Version(); !ok || ver != 1 {
		return nil, trace.BadParameter("'%v' is not a be a valid Time UUID v1", id)
	}
	uid := ID(id)
	return &uid, nil
}
644339
func tryToInt(v reflect.Value) (int, error) {
	if v.Kind() == reflect.Ptr || v.Kind() == reflect.Interface {
		v = v.Elem()
	}
	switch v.Kind() {
	case reflect.Float64, reflect.Float32:
		return int(v.Float()), nil
	case reflect.Int64, reflect.Int32, reflect.Int16, reflect.Int8, reflect.Int:
		return int(v.Int()), nil
	case reflect.Bool:
		if v.Bool() {
			return 1, nil
		}
		return 0, nil
	case reflect.String:
		s := v.String()
		var i int64
		var err error
		if strings.HasPrefix(s, "0x") {
			i, err = strconv.ParseInt(s, 16, 64)
		} else {
			i, err = strconv.ParseInt(s, 10, 64)
		}
		if err == nil {
			return int(i), nil
		}
	}
	return 0, errors.New("couldn't convert to integer")
}
610451
func MustParseInt64(s string) (i int64) {
	i, _ = strconv.ParseInt(s, 10, 64)
	return
}
200699
func ConvertInt32(str string) (int32, error) {
	i, err := strconv.ParseInt(str, 10, 32)
	if err != nil {
		return 0, err
	}
	return int32(i), nil
}
110932
func (p *parser) parseIdent() *ast.Ident {
	pos := p.pos
	name := "_"
	if p.tok == token.IDENT {
		name = string(p.lit)
		p.next()
	} else {
		p.expect(token.IDENT) // use expect() error handling
	}
	return &ast.Ident{pos, name, nil}
}
273861
func (fv FlagValues) Int(name string, defaultValue int) (int, error) {
	value, found := fv[name]
	if !found {
		return defaultValue, nil
	}
	i, err := strconv.Atoi(value)
	if err != nil {
		return 0, fmt.Errorf("flag %q: cannot parse integer from %q", name, value)
	}
	return i, nil
}
130895
func (po *Po) parseID(l string) {
	// Save current Translation buffer.
	po.saveBuffer()

	// Set id
	po.trBuffer.ID, _ = strconv.Unquote(strings.TrimSpace(strings.TrimPrefix(l, "msgid")))
}
1329866
func ParseYear(str string) (int16, error) {
	v, err := strconv.ParseInt(str, 10, 16)
	if err != nil {
		return 0, errors.Trace(err)
	}
	y := int16(v)

	if len(str) == 4 {
		// Nothing to do.
	} else if len(str) == 2 || len(str) == 1 {
		y = int16(adjustYear(int(y)))
	} else {
		return 0, errors.Trace(ErrInvalidYearFormat)
	}

	if y < MinYear || y > MaxYear {
		return 0, errors.Trace(ErrInvalidYearFormat)
	}

	return y, nil
}
1251745
func Int(name rune, value int, helpvalue ...string) *int {
	return CommandLine.Int(name, value, helpvalue...)
}
92577
func parseIntFloat(desc string) (string, interface{}) {
	// parse for ints
	i := 0
	for i < len(desc) {
		if desc[i] < '0' || desc[i] > '9' {
			break
		}
		i++
	}
	if i == 0 {
		return "", nil
	}

	intVal := int(0)
	_, err := fmt.Sscanf(desc[:i], "%d", &intVal)
	if err != nil {
		return "", nil
	}
	if len(desc) == i {
		return desc[:i], intVal
	}
	if desc[i] != '.' {
		return desc[:i], intVal
	}

	// parse for floats
	i++
	if i == len(desc) {
		return desc[:i], float64(intVal)
	}

	j := i
	for i < len(desc) {
		if desc[i] < '0' || desc[i] > '9' {
			break
		}
		i++
	}
	if j == i {
		return desc[:i], float64(intVal)
	}

	f := float64(0)
	if _, err = fmt.Sscanf(desc[:i], "%f", &f); err != nil {
		return "", nil
	}
	return desc[:i], f
}
1257841
func Parse(val string) IntOrString {
	i, err := strconv.Atoi(val)
	if err != nil {
		return FromString(val)
	}
	return FromInt(i)
}
571162
func ParseInt(b []byte) (int64, int) {
	i := 0
	neg := false
	if len(b) > 0 && (b[0] == '+' || b[0] == '-') {
		neg = b[0] == '-'
		i++
	}
	n := uint64(0)
	for i < len(b) {
		c := b[i]
		if n > math.MaxUint64/10 {
			return 0, 0
		} else if c >= '0' && c <= '9' {
			n *= 10
			n += uint64(c - '0')
		} else {
			break
		}
		i++
	}
	if !neg && n > uint64(math.MaxInt64) || n > uint64(math.MaxInt64)+1 {
		return 0, 0
	} else if neg {
		return -int64(n), i
	}
	return int64(n), i
}