MCPcopy Create free account
hub / github.com/cel-expr/cel-go / parsePrecision

Function parsePrecision

ext/formatting.go:875–900  ·  view source on GitHub ↗
(formatStr string, maxPrecision int)

Source from the content-addressed store, hash-verified

873}
874
875func parsePrecision(formatStr string, maxPrecision int) (int, *int, error) {
876 i := 0
877 if formatStr[i] != '.' {
878 return i, nil, nil
879 }
880 i++
881 var buffer strings.Builder
882 for {
883 if i >= len(formatStr) {
884 return -1, nil, errors.New("could not find end of precision specifier")
885 }
886 if !isASCIIDigit(rune(formatStr[i])) {
887 break
888 }
889 buffer.WriteByte(formatStr[i])
890 i++
891 }
892 precision, err := strconv.Atoi(buffer.String())
893 if err != nil {
894 return -1, nil, fmt.Errorf("error while converting precision to integer: %w", err)
895 }
896 if maxPrecision > 0 && precision > maxPrecision {
897 return -1, nil, fmt.Errorf("precision %d exceeds maximum allowed precision %d", precision, maxPrecision)
898 }
899 return i, &precision, nil
900}
901
902func isASCIIDigit(r rune) bool {
903 return r <= unicode.MaxASCII && unicode.IsDigit(r)

Callers 1

parseFormattingClauseFunction · 0.85

Calls 3

isASCIIDigitFunction · 0.85
NewMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected