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

Function parsePrecisionV2

ext/formatting_v2.go:765–793  ·  view source on GitHub ↗
(formatStr string, maxPrecision int)

Source from the content-addressed store, hash-verified

763}
764
765func parsePrecisionV2(formatStr string, maxPrecision int) (int, int, error) {
766 i := 0
767 if formatStr[i] != '.' {
768 return i, defaultPrecision, nil
769 }
770 i++
771 var buffer strings.Builder
772 for {
773 if i >= len(formatStr) {
774 return -1, -1, errors.New("could not find end of precision specifier")
775 }
776 if !isASCIIDigit(rune(formatStr[i])) {
777 break
778 }
779 buffer.WriteByte(formatStr[i])
780 i++
781 }
782 precision, err := strconv.Atoi(buffer.String())
783 if err != nil {
784 return -1, -1, fmt.Errorf("error while converting precision to integer: %w", err)
785 }
786 if precision < 0 {
787 return -1, -1, fmt.Errorf("negative precision: %d", precision)
788 }
789 if maxPrecision > 0 && precision > maxPrecision {
790 return -1, -1, fmt.Errorf("precision %d exceeds maximum allowed precision %d", precision, maxPrecision)
791 }
792 return i, precision, nil
793}

Callers 1

parseFormattingClauseV2Function · 0.85

Calls 3

isASCIIDigitFunction · 0.85
NewMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected