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

Method format

ext/formatting_v2.go:45–186  ·  view source on GitHub ↗
(arg ref.Val)

Source from the content-addressed store, hash-verified

43}
44
45func (af *appendingFormatterV2) format(arg ref.Val) error {
46 switch arg.Type() {
47 case types.BoolType:
48 argBool, ok := arg.Value().(bool)
49 if !ok {
50 return fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.BoolType)
51 }
52 af.buf = strconv.AppendBool(af.buf, argBool)
53 return nil
54 case types.IntType:
55 argInt, ok := arg.Value().(int64)
56 if !ok {
57 return fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.IntType)
58 }
59 af.buf = strconv.AppendInt(af.buf, argInt, 10)
60 return nil
61 case types.UintType:
62 argUint, ok := arg.Value().(uint64)
63 if !ok {
64 return fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.UintType)
65 }
66 af.buf = strconv.AppendUint(af.buf, argUint, 10)
67 return nil
68 case types.DoubleType:
69 argDbl, ok := arg.Value().(float64)
70 if !ok {
71 return fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.DoubleType)
72 }
73 if math.IsNaN(argDbl) {
74 af.buf = append(af.buf, "NaN"...)
75 return nil
76 }
77 if math.IsInf(argDbl, -1) {
78 af.buf = append(af.buf, "-Infinity"...)
79 return nil
80 }
81 if math.IsInf(argDbl, 1) {
82 af.buf = append(af.buf, "Infinity"...)
83 return nil
84 }
85 af.buf = strconv.AppendFloat(af.buf, argDbl, 'f', -1, 64)
86 return nil
87 case types.BytesType:
88 argBytes, ok := arg.Value().([]byte)
89 if !ok {
90 return fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.BytesType)
91 }
92 af.buf = append(af.buf, argBytes...)
93 return nil
94 case types.StringType:
95 argStr, ok := arg.Value().(string)
96 if !ok {
97 return fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.StringType)
98 }
99 af.buf = append(af.buf, argStr...)
100 return nil
101 case types.DurationType:
102 argDur, ok := arg.Value().(time.Duration)

Callers 1

formatStringV2Function · 0.95

Calls 9

formatStringV2Function · 0.85
stringFormatErrorV2Function · 0.85
TypeMethod · 0.65
ValueMethod · 0.65
IteratorMethod · 0.65
HasNextMethod · 0.65
NextMethod · 0.65
FindMethod · 0.65
TypeNameMethod · 0.65

Tested by

no test coverage detected