// IsUTFNumeric check if the string contains only unicode numbers of any kind.
// Numbers can be 0-9 but also Fractions ¾,Roman Ⅸ and Hangzhou 〩. Empty string is valid.
435585
func IsUTFNumeric(s string) bool {
	for _, v := range s {
		if unicode.IsNumber(v) == false {
			return false
		}
	}
	return true
}
777017
func (f BytesFunc) Alphanumeric(n int) ([]byte, error) {
	return f(n, ALPHANUMERIC)
}
950324
func GetNumBase(num string) (string, int) {
	switch {
	case len(num) == 0:
		return num, 10

	case len(num) > 1 && num[0] == '0':
		if num[1] == 'x' {
			return num[2:], 16
		}
		return num[1:], 8
	}
	return num, 10
}
463881
func LessNumericStrings(l, r string) bool {
	var lf, rf float64
	if _, err := fmt.Sscanf(l, "%f", &lf); err != nil {
		return LessStrings(l, r)
	} else if _, err := fmt.Sscanf(r, "%f", &rf); err != nil {
		return LessStrings(l, r)
	} else {
		return lf < rf
	}
}
297338
func isHexadecimal(ch rune) bool {
	return '0' <= ch && ch <= '9' || 'a' <= ch && ch <= 'f' || 'A' <= ch && ch <= 'F'
}
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
}
529140
func StringToUint32(from string) (uint32, error) {
	val, err := strconv.ParseUint(from, DefeultNumericBase, 32)
	return uint32(val), err
}
1289962
func is_digit(b []byte, i int) bool {
	return b[i] >= '0' && b[i] <= '9'
}
712166
func IsFormat(s string) bool {
	r := []rune(s)
	if len(r) != 2 {
		return false
	}
	switch r[1] {
	case 107, 108, 109, 110, 111, 114:
		return true
	}
	return false
}
556879
func isValidNumber(s string) bool {
	// This function implements the JSON numbers grammar.
	// See https://tools.ietf.org/html/rfc7159#section-6
	// and https://json.org/number.gif

	if s == "" {
		return false
	}

	// Optional -
	if s[0] == '-' {
		s = s[1:]
		if s == "" {
			return false
		}
	}

	// Digits
	switch {
	default:
		return false

	case s[0] == '0':
		s = s[1:]

	case '1' <= s[0] && s[0] <= '9':
		s = s[1:]
		for len(s) > 0 && '0' <= s[0] && s[0] <= '9' {
			s = s[1:]
		}
	}

	// . followed by 1 or more digits.
	if len(s) >= 2 && s[0] == '.' && '0' <= s[1] && s[1] <= '9' {
		s = s[2:]
		for len(s) > 0 && '0' <= s[0] && s[0] <= '9' {
			s = s[1:]
		}
	}

	// e or E followed by an optional - or + and
	// 1 or more digits.
	if len(s) >= 2 && (s[0] == 'e' || s[0] == 'E') {
		s = s[1:]
		if s[0] == '+' || s[0] == '-' {
			s = s[1:]
			if s == "" {
				return false
			}
		}
		for len(s) > 0 && '0' <= s[0] && s[0] <= '9' {
			s = s[1:]
		}
	}

	// Make sure we are at the end.
	return s == ""
}
1075038
func parseTwoNumeric(input string) (int, string) {
	if len(input) > 1 && input[0] == '0' {
		return 0, input[1:]
	}
	matched := twoDigitRegex.FindAllString(input, -1)
	if len(matched) == 0 {
		return 0, input
	}

	str := matched[0]
	v, err := strconv.ParseInt(str, 10, 64)
	if err != nil {
		return 0, input
	}
	return int(v), input[len(str):]
}
200242
func UnicodeType(str uint32) {
	cstr := C.uint(str)
	C.unicodeType(cstr)
}
731846
func ParseNumber(f interface{}) (uint32, error) {
	// Useful for tests
	if n, ok := f.(uint32); ok {
		return n, nil
	}

	s, ok := f.(string)
	if !ok {
		return 0, newParseError("expected a number, got a non-atom")
	}

	nbr, err := strconv.ParseUint(s, 10, 32)
	if err != nil {
		return 0, &parseError{err}
	}

	return uint32(nbr), nil
}
644662
func parseNumberString(nstr string) ([]int, error) {
	nstrs := strings.Split(nstr, ".")
	if len(nstrs) < 1 || len(nstrs) > 3 {
		return nil, errors.New(ErrIllegalVersionFormat, errorMessages, "wrong number parts")
	}
	vsn := []int{1, 0, 0}
	for i, nstr := range nstrs {
		num, err := strconv.Atoi(nstr)
		if err != nil {
			return nil, errors.New(ErrIllegalVersionFormat, errorMessages, err.Error())
		}
		if num < 0 {
			return nil, errors.New(ErrIllegalVersionFormat, errorMessages, "negative version number")
		}
		vsn[i] = num
	}
	return vsn, nil
}
887812
func newNumeric(v Value) (numeric, error) {
	str := v.ToString()
	switch {
	case v.IsSigned():
		ival, err := strconv.ParseInt(str, 10, 64)
		if err != nil {
			return numeric{}, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "%v", err)
		}
		return numeric{ival: ival, typ: Int64}, nil
	case v.IsUnsigned():
		uval, err := strconv.ParseUint(str, 10, 64)
		if err != nil {
			return numeric{}, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "%v", err)
		}
		return numeric{uval: uval, typ: Uint64}, nil
	case v.IsFloat():
		fval, err := strconv.ParseFloat(str, 64)
		if err != nil {
			return numeric{}, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "%v", err)
		}
		return numeric{fval: fval, typ: Float64}, nil
	}

	// For other types, do best effort.
	if ival, err := strconv.ParseInt(str, 10, 64); err == nil {
		return numeric{ival: ival, typ: Int64}, nil
	}
	if fval, err := strconv.ParseFloat(str, 64); err == nil {
		return numeric{fval: fval, typ: Float64}, nil
	}
	return numeric{}, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "could not parse value: '%s'", str)
}
894396
func (f URIFormatChecker) IsFormat(input interface{}) bool {
	asString, ok := input.(string)
	if !ok {
		return false
	}

	u, err := url.Parse(asString)

	if err != nil || u.Scheme == "" {
		return false
	}

	return !strings.Contains(asString, `\`)
}
489172
func typeIsNumeric(typ reflect.Type) bool {
	k := typ.Kind()
	switch k {
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Float32, reflect.Float64:
		return true
	default:
		return false
	}
}