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

Function FormatString

ext/formatting.go:210–229  ·  view source on GitHub ↗

FormatString returns the string representation of a CEL value. It is used to implement the %s specifier in the (string).format() extension function.

(arg ref.Val, locale string)

Source from the content-addressed store, hash-verified

208//
209// It is used to implement the %s specifier in the (string).format() extension function.
210func FormatString(arg ref.Val, locale string) (string, error) {
211 switch arg.Type() {
212 case types.ListType:
213 return formatList(arg, locale)
214 case types.MapType:
215 return formatMap(arg, locale)
216 case types.IntType, types.UintType, types.DoubleType,
217 types.BoolType, types.StringType, types.TimestampType, types.BytesType, types.DurationType, types.TypeType:
218 argStrVal := arg.ConvertToType(types.StringType)
219 argStr, ok := argStrVal.Value().(string)
220 if !ok {
221 return "", fmt.Errorf("could not convert argument %q to string", argStrVal)
222 }
223 return argStr, nil
224 case types.NullType:
225 return "null", nil
226 default:
227 return "", stringFormatError(runtimeID, arg.Type().TypeName())
228 }
229}
230
231func formatDecimal(arg ref.Val, locale string) (string, error) {
232 switch arg.Type() {

Callers 1

StringMethod · 0.85

Calls 7

stringFormatErrorFunction · 0.85
formatListFunction · 0.70
formatMapFunction · 0.70
TypeMethod · 0.65
ConvertToTypeMethod · 0.65
ValueMethod · 0.65
TypeNameMethod · 0.65

Tested by

no test coverage detected