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

Function quoteForCEL

ext/formatting.go:189–205  ·  view source on GitHub ↗

quoteForCEL takes a formatted, unquoted value and quotes it in a manner suitable for embedding directly in CEL.

(refVal ref.Val, unquotedValue string)

Source from the content-addressed store, hash-verified

187// quoteForCEL takes a formatted, unquoted value and quotes it in a manner suitable
188// for embedding directly in CEL.
189func quoteForCEL(refVal ref.Val, unquotedValue string) string {
190 switch refVal.Type() {
191 case types.StringType:
192 return fmt.Sprintf("%q", unquotedValue)
193 case types.BytesType:
194 return fmt.Sprintf("b%q", unquotedValue)
195 case types.DoubleType:
196 // special case to handle infinity/NaN
197 num := refVal.Value().(float64)
198 if math.IsInf(num, 1) || math.IsInf(num, -1) || math.IsNaN(num) {
199 return fmt.Sprintf("%q", unquotedValue)
200 }
201 return unquotedValue
202 default:
203 return unquotedValue
204 }
205}
206
207// FormatString returns the string representation of a CEL value.
208//

Callers 2

formatListFunction · 0.85
formatMapFunction · 0.85

Calls 2

TypeMethod · 0.65
ValueMethod · 0.65

Tested by

no test coverage detected