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

Function formatList

ext/formatting.go:82–117  ·  view source on GitHub ↗
(arg ref.Val, locale string)

Source from the content-addressed store, hash-verified

80}
81
82func formatList(arg ref.Val, locale string) (string, error) {
83 argList := arg.(traits.Lister)
84 argIterator := argList.Iterator()
85 var listStrBuilder strings.Builder
86 _, err := listStrBuilder.WriteRune('[')
87 if err != nil {
88 return "", fmt.Errorf("error writing to list string: %w", err)
89 }
90 for argIterator.HasNext() == types.True {
91 member := argIterator.Next()
92 memberFormat, err := clauseForType(member.Type())
93 if err != nil {
94 return "", err
95 }
96 unquotedStr, err := memberFormat(member, locale)
97 if err != nil {
98 return "", err
99 }
100 str := quoteForCEL(member, unquotedStr)
101 _, err = listStrBuilder.WriteString(str)
102 if err != nil {
103 return "", fmt.Errorf("error writing to list string: %w", err)
104 }
105 if argIterator.HasNext() == types.True {
106 _, err = listStrBuilder.WriteString(", ")
107 if err != nil {
108 return "", fmt.Errorf("error writing to list string: %w", err)
109 }
110 }
111 }
112 _, err = listStrBuilder.WriteRune(']')
113 if err != nil {
114 return "", fmt.Errorf("error writing to list string: %w", err)
115 }
116 return listStrBuilder.String(), nil
117}
118
119func formatMap(arg ref.Val, locale string) (string, error) {
120 argMap := arg.(traits.Mapper)

Callers 1

FormatStringFunction · 0.70

Calls 7

clauseForTypeFunction · 0.85
quoteForCELFunction · 0.85
IteratorMethod · 0.65
HasNextMethod · 0.65
NextMethod · 0.65
TypeMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected