Debian Codegraph @

ext/formatting.go

raw symbols SCIP
1 // Copyright 2023 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package extscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/
16
17 import (
18 "errorsscip-go gomod github.com/golang/go/src go1.23.0 errors/"
19 "fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/"
20 "mathscip-go gomod github.com/golang/go/src go1.23.0 math/"
21 "sortscip-go gomod github.com/golang/go/src go1.23.0 sort/"
22 "strconvscip-go gomod github.com/golang/go/src go1.23.0 strconv/"
23 "stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/"
24 "unicodescip-go gomod github.com/golang/go/src go1.23.0 unicode/"
25
26 "golang.org/x/text/languagescip-go gomod golang.org/x/text v0.22.0 `golang.org/x/text/language`/"
27 "golang.org/x/text/messagescip-go gomod golang.org/x/text v0.22.0 `golang.org/x/text/message`/"
28
29 "github.com/google/cel-go/celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/"
30 "github.com/google/cel-go/common/astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/"
31 "github.com/google/cel-go/common/overloadsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/overloads`/"
32 "github.com/google/cel-go/common/typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/"
33 "github.com/google/cel-go/common/types/refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/"
34 "github.com/google/cel-go/common/types/traitsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/traits`/"
35 )
36
37 type clauseImplscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/clauseImpl# func(refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, string) (string, error)
38
39 func clauseForTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/clauseForType().(argType refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Type#) (clauseImplscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/clauseImpl#, error) {
40 switch argType {
41 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.IntTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/IntType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.UintTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/UintType.:
42 return formatDecimalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatDecimal()., nil
43 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.StringTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/StringType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.BytesTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/BytesType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.BoolTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/BoolType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.NullTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/NullType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.TypeTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/TypeType.:
44 return FormatStringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/FormatString()., nil
45 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.TimestampTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/TimestampType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.DurationTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/DurationType.:
46 // special case to ensure timestamps/durations get printed as CEL literals
47 return func(arg refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, locale string) (string, error) {
48 argStrVal := arg.ConvertToTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#ConvertToType.(typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.StringTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/StringType.)
49 argStr := argStrVal.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().(string)
50 if arg.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.() == typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.TimestampTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/TimestampType. {
51 return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().("timestamp(%q)", argStr), nil
52 }
53 if arg.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.() == typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.DurationTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/DurationType. {
54 return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().("duration(%q)", argStr), nil
55 }
56 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("cannot convert argument of type %s to timestamp/duration", arg.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.().TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Type#TypeName.())
57 }, nil
58 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.ListTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/ListType.:
59 return formatListscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatList()., nil
60 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.MapTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/MapType.:
61 return formatMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatMap()., nil
62 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.DoubleTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/DoubleType.:
63 // avoid formatFixed so we can output a period as the decimal separator in order
64 // to always be a valid CEL literal
65 return func(arg refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, locale string) (string, error) {
66 argDouble, ok := arg.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().(float64)
67 if !ok {
68 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("couldn't convert %s to float64", arg.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.().TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Type#TypeName.())
69 }
70 fmtStr := fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().("%%.%df", defaultPrecisionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/defaultPrecision.)
71 return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().(fmtStr, argDouble), nil
72 }, nil
73 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.TypeTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/TypeType.:
74 return func(arg refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, locale string) (string, error) {
75 return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().("type(%s)", arg.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().(string)), nil
76 }, nil
77 default:
78 return nil, fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("no formatting function for %s", argType.TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Type#TypeName.())
79 }
80 }
81
82 func formatListscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatList().(arg refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, locale string) (string, error) {
83 argList := arg.(traitsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/traits`/.Listerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/traits`/Lister#)
84 argIterator := argList.Iteratorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/traits`/Iterable#Iterator.()
85 var listStrBuilder stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.Builderscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#
86 _, err := listStrBuilder.WriteRunescip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#WriteRune().('[')
87 if err != nil {
88 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("error writing to list string: %w", err)
89 }
90 for argIterator.HasNextscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/traits`/Iterator#HasNext.() == typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Truescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/True. {
91 member := argIterator.Nextscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/traits`/Iterator#Next.()
92 memberFormat, err := clauseForTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/clauseForType().(member.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#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 := quoteForCELscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/quoteForCEL().(member, unquotedStr)
101 _, err = listStrBuilder.WriteStringscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#WriteString().(str)
102 if err != nil {
103 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("error writing to list string: %w", err)
104 }
105 if argIterator.HasNextscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/traits`/Iterator#HasNext.() == typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Truescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/True. {
106 _, err = listStrBuilder.WriteStringscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#WriteString().(", ")
107 if err != nil {
108 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("error writing to list string: %w", err)
109 }
110 }
111 }
112 _, err = listStrBuilder.WriteRunescip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#WriteRune().(']')
113 if err != nil {
114 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("error writing to list string: %w", err)
115 }
116 return listStrBuilder.Stringscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#String().(), nil
117 }
118
119 func formatMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatMap().(arg refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, locale string) (string, error) {
120 argMap := arg.(traitsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/traits`/.Mapperscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/traits`/Mapper#)
121 argIterator := argMap.Iteratorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/traits`/Iterable#Iterator.()
122 type mapPair struct {
123 key string
124 value string
125 }
126 argPairs := make([]mapPair, argMap.Sizescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/traits`/Sizer#Size.().Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().(int64))
127 i := 0
128 for argIterator.HasNextscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/traits`/Iterator#HasNext.() == typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Truescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/True. {
129 key := argIterator.Nextscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/traits`/Iterator#Next.()
130 var keyFormat clauseImplscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/clauseImpl#
131 switch key.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.() {
132 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.StringTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/StringType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.BoolTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/BoolType.:
133 keyFormat = FormatStringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/FormatString().
134 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.IntTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/IntType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.UintTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/UintType.:
135 keyFormat = formatDecimalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatDecimal().
136 default:
137 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("no formatting function for map key of type %s", key.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.().TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Type#TypeName.())
138 }
139 unquotedKeyStr, err := keyFormat(key, locale)
140 if err != nil {
141 return "", err
142 }
143 keyStr := quoteForCELscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/quoteForCEL().(key, unquotedKeyStr)
144 value, found := argMap.Findscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/traits`/Mapper#Find.(key)
145 if !found {
146 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("could not find key: %q", key)
147 }
148 valueFormat, err := clauseForTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/clauseForType().(value.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.())
149 if err != nil {
150 return "", err
151 }
152 unquotedValueStr, err := valueFormat(value, locale)
153 if err != nil {
154 return "", err
155 }
156 valueStr := quoteForCELscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/quoteForCEL().(value, unquotedValueStr)
157 argPairs[i] = mapPair{keyStr, valueStr}
158 i++
159 }
160 sortscip-go gomod github.com/golang/go/src go1.23.0 sort/.SliceStablescip-go gomod github.com/golang/go/src go1.23.0 sort/SliceStable().(argPairs, func(x, y int) bool {
161 return argPairs[x].key < argPairs[y].key
162 })
163 var mapStrBuilder stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.Builderscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#
164 _, err := mapStrBuilder.WriteRunescip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#WriteRune().('{')
165 if err != nil {
166 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("error writing to map string: %w", err)
167 }
168 for i, entry := range argPairs {
169 _, err = mapStrBuilder.WriteStringscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#WriteString().(fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().("%s:%s", entry.key, entry.value))
170 if err != nil {
171 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("error writing to map string: %w", err)
172 }
173 if i < len(argPairs)-1 {
174 _, err = mapStrBuilder.WriteStringscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#WriteString().(", ")
175 if err != nil {
176 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("error writing to map string: %w", err)
177 }
178 }
179 }
180 _, err = mapStrBuilder.WriteRunescip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#WriteRune().('}')
181 if err != nil {
182 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("error writing to map string: %w", err)
183 }
184 return mapStrBuilder.Stringscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#String().(), nil
185 }
186
187 // quoteForCEL takes a formatted, unquoted value and quotes it in a manner suitable
188 // for embedding directly in CEL.
189 func quoteForCELscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/quoteForCEL().(refVal refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, unquotedValue string) string {
190 switch refVal.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.() {
191 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.StringTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/StringType.:
192 return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().("%q", unquotedValue)
193 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.BytesTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/BytesType.:
194 return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().("b%q", unquotedValue)
195 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.DoubleTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/DoubleType.:
196 // special case to handle infinity/NaN
197 num := refVal.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().(float64)
198 if mathscip-go gomod github.com/golang/go/src go1.23.0 math/.IsInfscip-go gomod github.com/golang/go/src go1.23.0 math/IsInf().(num, 1) || mathscip-go gomod github.com/golang/go/src go1.23.0 math/.IsInfscip-go gomod github.com/golang/go/src go1.23.0 math/IsInf().(num, -1) || mathscip-go gomod github.com/golang/go/src go1.23.0 math/.IsNaNscip-go gomod github.com/golang/go/src go1.23.0 math/IsNaN().(num) {
199 return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 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 //
209 // It is used to implement the %s specifier in the (string).format() extension function.
210 func FormatStringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/FormatString().(arg refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, locale string) (string, error) {
211 switch arg.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.() {
212 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.ListTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/ListType.:
213 return formatListscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatList().(arg, locale)
214 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.MapTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/MapType.:
215 return formatMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatMap().(arg, locale)
216 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.IntTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/IntType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.UintTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/UintType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.DoubleTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/DoubleType.,
217 typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.BoolTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/BoolType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.StringTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/StringType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.TimestampTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/TimestampType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.BytesTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/BytesType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.DurationTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/DurationType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.TypeTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/TypeType.:
218 argStrVal := arg.ConvertToTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#ConvertToType.(typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.StringTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/StringType.)
219 argStr, ok := argStrVal.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().(string)
220 if !ok {
221 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("could not convert argument %q to string", argStrVal)
222 }
223 return argStr, nil
224 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.NullTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/NullType.:
225 return "null", nil
226 default:
227 return "", stringFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatError().(runtimeIDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/runtimeID., arg.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.().TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Type#TypeName.())
228 }
229 }
230
231 func formatDecimalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatDecimal().(arg refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, locale string) (string, error) {
232 switch arg.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.() {
233 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.IntTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/IntType.:
234 argInt, ok := arg.ConvertToTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#ConvertToType.(typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.IntTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/IntType.).Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().(int64)
235 if !ok {
236 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("could not convert \"%s\" to int64", arg.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.())
237 }
238 return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().("%d", argInt), nil
239 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.UintTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/UintType.:
240 argInt, ok := arg.ConvertToTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#ConvertToType.(typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.UintTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/UintType.).Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().(uint64)
241 if !ok {
242 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("could not convert \"%s\" to uint64", arg.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.())
243 }
244 return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().("%d", argInt), nil
245 default:
246 return "", decimalFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/decimalFormatError().(runtimeIDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/runtimeID., arg.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.().TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Type#TypeName.())
247 }
248 }
249
250 func matchLanguagescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/matchLanguage().(locale string) (languagescip-go gomod golang.org/x/text v0.22.0 `golang.org/x/text/language`/.Tagscip-go gomod golang.org/x/text v0.22.0 `golang.org/x/text/language`/Tag#, error) {
251 matcher, err := makeMatcherscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/makeMatcher().(locale)
252 if err != nil {
253 return languagescip-go gomod golang.org/x/text v0.22.0 `golang.org/x/text/language`/.Undscip-go gomod golang.org/x/text v0.22.0 `golang.org/x/text/language`/Und., err
254 }
255 tag, _ := languagescip-go gomod golang.org/x/text v0.22.0 `golang.org/x/text/language`/.MatchStringsscip-go gomod golang.org/x/text v0.22.0 `golang.org/x/text/language`/MatchStrings().(matcher, locale)
256 return tag, nil
257 }
258
259 func makeMatcherscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/makeMatcher().(locale string) (languagescip-go gomod golang.org/x/text v0.22.0 `golang.org/x/text/language`/.Matcherscip-go gomod golang.org/x/text v0.22.0 `golang.org/x/text/language`/Matcher#, error) {
260 tags := make([]languagescip-go gomod golang.org/x/text v0.22.0 `golang.org/x/text/language`/.Tagscip-go gomod golang.org/x/text v0.22.0 `golang.org/x/text/language`/Tag#, 0)
261 tag, err := languagescip-go gomod golang.org/x/text v0.22.0 `golang.org/x/text/language`/.Parsescip-go gomod golang.org/x/text v0.22.0 `golang.org/x/text/language`/Parse().(locale)
262 if err != nil {
263 return nil, err
264 }
265 tags = append(tags, tag)
266 return languagescip-go gomod golang.org/x/text v0.22.0 `golang.org/x/text/language`/.NewMatcherscip-go gomod golang.org/x/text v0.22.0 `golang.org/x/text/language`/NewMatcher().(tags), nil
267 }
268
269 type stringFormatterscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatter# struct{}
270
271 // String implements formatStringInterpolator.String.
272 func (c *stringFormatterscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatter#) Stringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatter#String().(arg refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, locale string) (string, error) {
273 return FormatStringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/FormatString().(arg, locale)
274 }
275
276 // Decimal implements formatStringInterpolator.Decimal.
277 func (c *stringFormatterscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatter#) Decimalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatter#Decimal().(arg refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, locale string) (string, error) {
278 return formatDecimalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatDecimal().(arg, locale)
279 }
280
281 // Fixed implements formatStringInterpolator.Fixed.
282 func (c *stringFormatterscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatter#) Fixedscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatter#Fixed().(precision *int) func(refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, string) (string, error) {
283 if precision == nil {
284 precision = new(int)
285 *precision = defaultPrecisionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/defaultPrecision.
286 }
287 return func(arg refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, locale string) (string, error) {
288 strException := false
289 if arg.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.() == typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.StringTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/StringType. {
290 argStr := arg.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().(string)
291 if argStr == "NaN" || argStr == "Infinity" || argStr == "-Infinity" {
292 strException = true
293 }
294 }
295 if arg.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.() != typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.DoubleTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/DoubleType. && !strException {
296 return "", fixedPointFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/fixedPointFormatError().(runtimeIDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/runtimeID., arg.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.().TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Type#TypeName.())
297 }
298 argFloatVal := arg.ConvertToTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#ConvertToType.(typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.DoubleTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/DoubleType.)
299 argFloat, ok := argFloatVal.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().(float64)
300 if !ok {
301 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("could not convert \"%s\" to float64", argFloatVal.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.())
302 }
303 fmtStr := fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().("%%.%df", *precision)
304
305 matchedLocale, err := matchLanguagescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/matchLanguage().(locale)
306 if err != nil {
307 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("error matching locale: %w", err)
308 }
309 return messagescip-go gomod golang.org/x/text v0.22.0 `golang.org/x/text/message`/.NewPrinterscip-go gomod golang.org/x/text v0.22.0 `golang.org/x/text/message`/NewPrinter().(matchedLocale).Sprintfscip-go gomod golang.org/x/text v0.22.0 `golang.org/x/text/message`/Printer#Sprintf().(fmtStr, argFloat), nil
310 }
311 }
312
313 // Scientific implements formatStringInterpolator.Scientific.
314 func (c *stringFormatterscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatter#) Scientificscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatter#Scientific().(precision *int) func(refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, string) (string, error) {
315 if precision == nil {
316 precision = new(int)
317 *precision = defaultPrecisionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/defaultPrecision.
318 }
319 return func(arg refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, locale string) (string, error) {
320 strException := false
321 if arg.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.() == typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.StringTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/StringType. {
322 argStr := arg.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().(string)
323 if argStr == "NaN" || argStr == "Infinity" || argStr == "-Infinity" {
324 strException = true
325 }
326 }
327 if arg.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.() != typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.DoubleTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/DoubleType. && !strException {
328 return "", scientificFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/scientificFormatError().(runtimeIDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/runtimeID., arg.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.().TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Type#TypeName.())
329 }
330 argFloatVal := arg.ConvertToTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#ConvertToType.(typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.DoubleTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/DoubleType.)
331 argFloat, ok := argFloatVal.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().(float64)
332 if !ok {
333 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("could not convert \"%v\" to float64", argFloatVal.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.())
334 }
335 matchedLocale, err := matchLanguagescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/matchLanguage().(locale)
336 if err != nil {
337 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("error matching locale: %w", err)
338 }
339 fmtStr := fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().("%%%de", *precision)
340 return messagescip-go gomod golang.org/x/text v0.22.0 `golang.org/x/text/message`/.NewPrinterscip-go gomod golang.org/x/text v0.22.0 `golang.org/x/text/message`/NewPrinter().(matchedLocale).Sprintfscip-go gomod golang.org/x/text v0.22.0 `golang.org/x/text/message`/Printer#Sprintf().(fmtStr, argFloat), nil
341 }
342 }
343
344 // Binary implements formatStringInterpolator.Binary.
345 func (c *stringFormatterscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatter#) Binaryscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatter#Binary().(arg refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, locale string) (string, error) {
346 switch arg.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.() {
347 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.IntTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/IntType.:
348 argInt := arg.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().(int64)
349 // locale is intentionally unused as integers formatted as binary
350 // strings are locale-independent
351 return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().("%b", argInt), nil
352 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.UintTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/UintType.:
353 argInt := arg.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().(uint64)
354 return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().("%b", argInt), nil
355 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.BoolTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/BoolType.:
356 argBool := arg.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().(bool)
357 if argBool {
358 return "1", nil
359 }
360 return "0", nil
361 default:
362 return "", binaryFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/binaryFormatError().(runtimeIDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/runtimeID., arg.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.().TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Type#TypeName.())
363 }
364 }
365
366 // Hex implements formatStringInterpolator.Hex.
367 func (c *stringFormatterscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatter#) Hexscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatter#Hex().(useUpper bool) func(refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, string) (string, error) {
368 return func(arg refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, locale string) (string, error) {
369 fmtStr := "%x"
370 if useUpper {
371 fmtStr = "%X"
372 }
373 switch arg.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.() {
374 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.StringTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/StringType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.BytesTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/BytesType.:
375 if arg.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.() == typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.BytesTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/BytesType. {
376 return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().(fmtStr, arg.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().([]byte)), nil
377 }
378 return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().(fmtStr, arg.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().(string)), nil
379 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.IntTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/IntType.:
380 argInt, ok := arg.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().(int64)
381 if !ok {
382 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("could not convert \"%s\" to int64", arg.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.())
383 }
384 return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().(fmtStr, argInt), nil
385 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.UintTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/UintType.:
386 argInt, ok := arg.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().(uint64)
387 if !ok {
388 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("could not convert \"%s\" to uint64", arg.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.())
389 }
390 return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().(fmtStr, argInt), nil
391 default:
392 return "", hexFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/hexFormatError().(runtimeIDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/runtimeID., arg.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.().TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Type#TypeName.())
393 }
394 }
395 }
396
397 // Octal implements formatStringInterpolator.Octal.
398 func (c *stringFormatterscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatter#) Octalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatter#Octal().(arg refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, locale string) (string, error) {
399 switch arg.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.() {
400 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.IntTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/IntType.:
401 argInt := arg.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().(int64)
402 return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().("%o", argInt), nil
403 case typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.UintTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/UintType.:
404 argInt := arg.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().(uint64)
405 return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().("%o", argInt), nil
406 default:
407 return "", octalFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/octalFormatError().(runtimeIDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/runtimeID., arg.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.().TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Type#TypeName.())
408 }
409 }
410
411 // stringFormatValidator implements the cel.ASTValidator interface allowing for static validation
412 // of string.format calls.
413 type stringFormatValidatorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatValidator# struct{}
414
415 // Name returns the name of the validator.
416 func (stringFormatValidatorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatValidator#) Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatValidator#Name().() string {
417 return "cel.validator.string_format"
418 }
419
420 // Configure implements the ASTValidatorConfigurer interface and augments the list of functions to skip
421 // during homogeneous aggregate literal type-checks.
422 func (stringFormatValidatorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatValidator#) Configurescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatValidator#Configure().(config celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.MutableValidatorConfigscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/MutableValidatorConfig#) error {
423 functions := config.GetOrDefaultscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/ValidatorConfig#GetOrDefault.(celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.HomogeneousAggregateLiteralExemptFunctionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/HomogeneousAggregateLiteralExemptFunctions., []string{}).([]string)
424 functions = append(functions, "format")
425 return config.Setscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/MutableValidatorConfig#Set.(celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.HomogeneousAggregateLiteralExemptFunctionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/HomogeneousAggregateLiteralExemptFunctions., functions)
426 }
427
428 // Validate parses all literal format strings and type checks the format clause against the argument
429 // at the corresponding ordinal within the list literal argument to the function, if one is specified.
430 func (stringFormatValidatorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatValidator#) Validatescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatValidator#Validate().(env *celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.Envscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Env#, _ celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.ValidatorConfigscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/ValidatorConfig#, a *astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.ASTscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/AST#, iss *celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.Issuesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Issues#) {
431 root := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigateASTscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigateAST().(a)
432 formatCallExprs := astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.MatchDescendantsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MatchDescendants().(root, matchConstantFormatStringWithListLiteralArgsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/matchConstantFormatStringWithListLiteralArgs().(a))
433 for _, e := range formatCallExprs {
434 call := e.AsCallscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsCall.()
435 formatStr := call.Targetscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallExpr#Target.().AsLiteralscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsLiteral.().Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().(string)
436 args := call.Argsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallExpr#Args.()[0].AsListscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsList.().Elementsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ListExpr#Elements.()
437 formatCheck := &stringFormatCheckerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#{
438 argsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#args.: args,
439 astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#ast.: a,
440 }
441 // use a placeholder locale, since locale doesn't affect syntax
442 _, err := parseFormatStringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parseFormatString().(formatStr, formatCheck, formatCheck, "en_US")
443 if err != nil {
444 iss.ReportErrorAtIDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Issues#ReportErrorAtID().(getErrorExprIDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/getErrorExprID().(e.IDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#ID.(), err), "%v", err)
445 continue
446 }
447 seenArgs := formatCheck.argsRequestedscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#argsRequested.
448 if len(args) > seenArgs {
449 iss.ReportErrorAtIDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Issues#ReportErrorAtID().(e.IDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#ID.(),
450 "too many arguments supplied to string.format (expected %d, got %d)", seenArgs, len(args))
451 }
452 }
453 }
454
455 // getErrorExprID determines which list literal argument triggered a type-disagreement for the
456 // purposes of more accurate error message reports.
457 func getErrorExprIDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/getErrorExprID().(id int64, err error) int64 {
458 fmtErr, ok := err.(formatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatError#)
459 if ok {
460 return fmtErr.idscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatError#id.
461 }
462 wrapped := errorsscip-go gomod github.com/golang/go/src go1.23.0 errors/.Unwrapscip-go gomod github.com/golang/go/src go1.23.0 errors/Unwrap().(err)
463 if wrapped != nil {
464 return getErrorExprIDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/getErrorExprID().(id, wrapped)
465 }
466 return id
467 }
468
469 // matchConstantFormatStringWithListLiteralArgs matches all valid expression nodes for string
470 // format checking.
471 func matchConstantFormatStringWithListLiteralArgsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/matchConstantFormatStringWithListLiteralArgs().(a *astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.ASTscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/AST#) astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.ExprMatcherscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ExprMatcher# {
472 return func(e astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.NavigableExprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/NavigableExpr#) bool {
473 if e.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.() != astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.CallKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallKind. {
474 return false
475 }
476 call := e.AsCallscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsCall.()
477 if !call.IsMemberFunctionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallExpr#IsMemberFunction.() || call.FunctionNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallExpr#FunctionName.() != "format" {
478 return false
479 }
480 overloadIDs := a.GetOverloadIDsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/AST#GetOverloadIDs().(e.IDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#ID.())
481 if len(overloadIDs) != 0 {
482 found := false
483 for _, overload := range overloadIDs {
484 if overload == overloadsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/overloads`/.ExtFormatStringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/overloads`/ExtFormatString. {
485 found = true
486 break
487 }
488 }
489 if !found {
490 return false
491 }
492 }
493 formatString := call.Targetscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallExpr#Target.()
494 if formatString.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.() != astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.LiteralKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/LiteralKind. || formatString.AsLiteralscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsLiteral.().Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Type.() != celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.StringTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/StringType. {
495 return false
496 }
497 args := call.Argsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/CallExpr#Args.()
498 if len(args) != 1 {
499 return false
500 }
501 formatArgs := args[0]
502 return formatArgs.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.() == astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.ListKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ListKind.
503 }
504 }
505
506 // stringFormatChecker implements the formatStringInterpolater interface
507 type stringFormatCheckerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker# struct {
508 argsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#args. []astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.Exprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#
509 argsRequestedscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#argsRequested. int
510 currArgIndexscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#currArgIndex. int64
511 astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#ast. *astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.ASTscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/AST#
512 }
513
514 // String implements formatStringInterpolator.String.
515 func (c *stringFormatCheckerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#) Stringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#String().(arg refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, locale string) (string, error) {
516 formatArg := c.argsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#args.[c.currArgIndexscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#currArgIndex.]
517 valid, badID := c.verifyStringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#verifyString().(formatArg)
518 if !valid {
519 return "", stringFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatError().(badID, c.typeOfscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#typeOf().(badID).TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#TypeName().())
520 }
521 return "", nil
522 }
523
524 // Decimal implements formatStringInterpolator.Decimal.
525 func (c *stringFormatCheckerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#) Decimalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#Decimal().(arg refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, locale string) (string, error) {
526 id := c.argsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#args.[c.currArgIndexscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#currArgIndex.].IDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#ID.()
527 valid := c.verifyTypeOneOfscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#verifyTypeOneOf().(id, typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.IntTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/IntType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.UintTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/UintType.)
528 if !valid {
529 return "", decimalFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/decimalFormatError().(id, c.typeOfscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#typeOf().(id).TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#TypeName().())
530 }
531 return "", nil
532 }
533
534 // Fixed implements formatStringInterpolator.Fixed.
535 func (c *stringFormatCheckerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#) Fixedscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#Fixed().(precision *int) func(refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, string) (string, error) {
536 return func(arg refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, locale string) (string, error) {
537 id := c.argsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#args.[c.currArgIndexscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#currArgIndex.].IDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#ID.()
538 // we allow StringType since "NaN", "Infinity", and "-Infinity" are also valid values
539 valid := c.verifyTypeOneOfscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#verifyTypeOneOf().(id, typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.DoubleTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/DoubleType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.StringTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/StringType.)
540 if !valid {
541 return "", fixedPointFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/fixedPointFormatError().(id, c.typeOfscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#typeOf().(id).TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#TypeName().())
542 }
543 return "", nil
544 }
545 }
546
547 // Scientific implements formatStringInterpolator.Scientific.
548 func (c *stringFormatCheckerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#) Scientificscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#Scientific().(precision *int) func(refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, string) (string, error) {
549 return func(arg refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, locale string) (string, error) {
550 id := c.argsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#args.[c.currArgIndexscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#currArgIndex.].IDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#ID.()
551 valid := c.verifyTypeOneOfscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#verifyTypeOneOf().(id, typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.DoubleTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/DoubleType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.StringTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/StringType.)
552 if !valid {
553 return "", scientificFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/scientificFormatError().(id, c.typeOfscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#typeOf().(id).TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#TypeName().())
554 }
555 return "", nil
556 }
557 }
558
559 // Binary implements formatStringInterpolator.Binary.
560 func (c *stringFormatCheckerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#) Binaryscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#Binary().(arg refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, locale string) (string, error) {
561 id := c.argsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#args.[c.currArgIndexscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#currArgIndex.].IDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#ID.()
562 valid := c.verifyTypeOneOfscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#verifyTypeOneOf().(id, typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.IntTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/IntType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.UintTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/UintType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.BoolTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/BoolType.)
563 if !valid {
564 return "", binaryFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/binaryFormatError().(id, c.typeOfscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#typeOf().(id).TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#TypeName().())
565 }
566 return "", nil
567 }
568
569 // Hex implements formatStringInterpolator.Hex.
570 func (c *stringFormatCheckerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#) Hexscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#Hex().(useUpper bool) func(refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, string) (string, error) {
571 return func(arg refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, locale string) (string, error) {
572 id := c.argsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#args.[c.currArgIndexscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#currArgIndex.].IDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#ID.()
573 valid := c.verifyTypeOneOfscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#verifyTypeOneOf().(id, typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.IntTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/IntType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.UintTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/UintType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.StringTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/StringType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.BytesTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/BytesType.)
574 if !valid {
575 return "", hexFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/hexFormatError().(id, c.typeOfscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#typeOf().(id).TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#TypeName().())
576 }
577 return "", nil
578 }
579 }
580
581 // Octal implements formatStringInterpolator.Octal.
582 func (c *stringFormatCheckerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#) Octalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#Octal().(arg refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, locale string) (string, error) {
583 id := c.argsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#args.[c.currArgIndexscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#currArgIndex.].IDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#ID.()
584 valid := c.verifyTypeOneOfscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#verifyTypeOneOf().(id, typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.IntTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/IntType., typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.UintTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/UintType.)
585 if !valid {
586 return "", octalFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/octalFormatError().(id, c.typeOfscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#typeOf().(id).TypeNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#TypeName().())
587 }
588 return "", nil
589 }
590
591 // Arg implements formatListArgs.Arg.
592 func (c *stringFormatCheckerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#) Argscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#Arg().(index int64) (refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, error) {
593 c.argsRequestedscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#argsRequested.++
594 c.currArgIndexscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#currArgIndex. = index
595 // return a dummy value - this is immediately passed to back to us
596 // through one of the FormatCallback functions, so anything will do
597 return typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Intscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Int#(0), nil
598 }
599
600 // Size implements formatListArgs.Size.
601 func (c *stringFormatCheckerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#) Sizescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#Size().() int64 {
602 return int64(len(c.argsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#args.))
603 }
604
605 func (c *stringFormatCheckerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#) typeOfscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#typeOf().(id int64) *celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Type# {
606 return c.astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#ast..GetTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/AST#GetType().(id)
607 }
608
609 func (c *stringFormatCheckerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#) verifyTypeOneOfscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#verifyTypeOneOf().(id int64, validTypes ...*celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.Typescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Type#) bool {
610 t := c.typeOfscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#typeOf().(id)
611 if t == celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.DynTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/DynType. {
612 return true
613 }
614 for _, vt := range validTypes {
615 // Only check runtime type compatibility without delving deeper into parameterized types
616 if t.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Kind().() == vt.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Type#Kind().() {
617 return true
618 }
619 }
620 return false
621 }
622
623 func (c *stringFormatCheckerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#) verifyStringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#verifyString().(sub astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.Exprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#) (bool, int64) {
624 paramA := celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.TypeParamTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/TypeParamType.("A")
625 paramB := celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.TypeParamTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/TypeParamType.("B")
626 subVerified := c.verifyTypeOneOfscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#verifyTypeOneOf().(sub.IDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#ID.(),
627 celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.ListTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/ListType.(paramA), celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.MapTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/MapType.(paramA, paramB),
628 celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.IntTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/IntType., celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.UintTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/UintType., celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.DoubleTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/DoubleType., celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.BoolTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/BoolType., celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.StringTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/StringType.,
629 celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.TimestampTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/TimestampType., celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.BytesTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/BytesType., celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.DurationTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/DurationType., celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.TypeTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/TypeType., celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.NullTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/NullType.)
630 if !subVerified {
631 return false, sub.IDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#ID.()
632 }
633 switch sub.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#Kind.() {
634 case astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.ListKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ListKind.:
635 for _, e := range sub.AsListscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsList.().Elementsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/ListExpr#Elements.() {
636 // recursively verify if we're dealing with a list/map
637 verified, id := c.verifyStringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#verifyString().(e)
638 if !verified {
639 return false, id
640 }
641 }
642 return true, sub.IDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#ID.()
643 case astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.MapKindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MapKind.:
644 for _, e := range sub.AsMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#AsMap.().Entriesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MapExpr#Entries.() {
645 // recursively verify if we're dealing with a list/map
646 entry := e.AsMapEntryscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/EntryExpr#AsMapEntry.()
647 verified, id := c.verifyStringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#verifyString().(entry.Keyscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MapEntry#Key.())
648 if !verified {
649 return false, id
650 }
651 verified, id = c.verifyStringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatChecker#verifyString().(entry.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/MapEntry#Value.())
652 if !verified {
653 return false, id
654 }
655 }
656 return true, sub.IDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#ID.()
657 default:
658 return true, sub.IDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#ID.()
659 }
660 }
661
662 // helper routines for reporting common errors during string formatting static validation and
663 // runtime execution.
664
665 func binaryFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/binaryFormatError().(id int64, badType string) error {
666 return newFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/newFormatError().(id, "only integers and bools can be formatted as binary, was given %s", badType)
667 }
668
669 func decimalFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/decimalFormatError().(id int64, badType string) error {
670 return newFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/newFormatError().(id, "decimal clause can only be used on integers, was given %s", badType)
671 }
672
673 func fixedPointFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/fixedPointFormatError().(id int64, badType string) error {
674 return newFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/newFormatError().(id, "fixed-point clause can only be used on doubles, was given %s", badType)
675 }
676
677 func hexFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/hexFormatError().(id int64, badType string) error {
678 return newFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/newFormatError().(id, "only integers, byte buffers, and strings can be formatted as hex, was given %s", badType)
679 }
680
681 func octalFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/octalFormatError().(id int64, badType string) error {
682 return newFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/newFormatError().(id, "octal clause can only be used on integers, was given %s", badType)
683 }
684
685 func scientificFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/scientificFormatError().(id int64, badType string) error {
686 return newFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/newFormatError().(id, "scientific clause can only be used on doubles, was given %s", badType)
687 }
688
689 func stringFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringFormatError().(id int64, badType string) error {
690 return newFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/newFormatError().(id, "string clause can only be used on strings, bools, bytes, ints, doubles, maps, lists, types, durations, and timestamps, was given %s", badType)
691 }
692
693 type formatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatError# struct {
694 idscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatError#id. int64
695 msgscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatError#msg. string
696 }
697
698 func newFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/newFormatError().(id int64, msg string, args ...any) error {
699 return formatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatError#{
700 idscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatError#id.: id,
701 msgscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatError#msg.: fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().(msg, args...),
702 }
703 }
704
705 // Error implements error.
706 func (e formatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatError#) Errorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatError#Error().() string {
707 return e.msgscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatError#msg.
708 }
709
710 // Is implements errors.Is.
711 func (e formatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatError#) Isscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatError#Is().(target error) bool {
712 return e.msgscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatError#msg. == target.Error()
713 }
714
715 // stringArgList implements the formatListArgs interface.
716 type stringArgListscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringArgList# struct {
717 argsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringArgList#args. traitsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/traits`/.Listerscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/traits`/Lister#
718 }
719
720 // Arg implements formatListArgs.Arg.
721 func (c *stringArgListscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringArgList#) Argscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringArgList#Arg().(index int64) (refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, error) {
722 if index >= c.argsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringArgList#args..Sizescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/traits`/Sizer#Size.().Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().(int64) {
723 return nil, fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("index %d out of range", index)
724 }
725 return c.argsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringArgList#args..Getscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/traits`/Indexer#Get.(typesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/.Intscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types`/Int#(index)), nil
726 }
727
728 // Size implements formatListArgs.Size.
729 func (c *stringArgListscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringArgList#) Sizescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringArgList#Size().() int64 {
730 return c.argsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/stringArgList#args..Sizescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/traits`/Sizer#Size.().Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.().(int64)
731 }
732
733 // formatStringInterpolator is an interface that allows user-defined behavior
734 // for formatting clause implementations, as well as argument retrieval.
735 // Each function is expected to support the appropriate types as laid out in
736 // the string.format documentation, and to return an error if given an inappropriate type.
737 type formatStringInterpolatorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatStringInterpolator# interface {
738 // String takes a ref.Val and a string representing the current locale identifier
739 // and returns the Val formatted as a string, or an error if one occurred.
740 Stringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatStringInterpolator#String.(refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, string) (string, error)
741
742 // Decimal takes a ref.Val and a string representing the current locale identifier
743 // and returns the Val formatted as a decimal integer, or an error if one occurred.
744 Decimalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatStringInterpolator#Decimal.(refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, string) (string, error)
745
746 // Fixed takes an int pointer representing precision (or nil if none was given) and
747 // returns a function operating in a similar manner to String and Decimal, taking a
748 // ref.Val and locale and returning the appropriate string. A closure is returned
749 // so precision can be set without needing an additional function call/configuration.
750 Fixedscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatStringInterpolator#Fixed.(*int) func(refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, string) (string, error)
751
752 // Scientific functions identically to Fixed, except the string returned from the closure
753 // is expected to be in scientific notation.
754 Scientificscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatStringInterpolator#Scientific.(*int) func(refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, string) (string, error)
755
756 // Binary takes a ref.Val and a string representing the current locale identifier
757 // and returns the Val formatted as a binary integer, or an error if one occurred.
758 Binaryscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatStringInterpolator#Binary.(refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, string) (string, error)
759
760 // Hex takes a boolean that, if true, indicates the hex string output by the returned
761 // closure should use uppercase letters for A-F.
762 Hexscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatStringInterpolator#Hex.(bool) func(refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, string) (string, error)
763
764 // Octal takes a ref.Val and a string representing the current locale identifier and
765 // returns the Val formatted in octal, or an error if one occurred.
766 Octalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatStringInterpolator#Octal.(refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, string) (string, error)
767 }
768
769 // formatListArgs is an interface that allows user-defined list-like datatypes to be used
770 // for formatting clause implementations.
771 type formatListArgsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatListArgs# interface {
772 // Arg returns the ref.Val at the given index, or an error if one occurred.
773 Argscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatListArgs#Arg.(int64) (refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, error)
774
775 // Size returns the length of the argument list.
776 Sizescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatListArgs#Size.() int64
777 }
778
779 // parseFormatString formats a string according to the string.format syntax, taking the clause implementations
780 // from the provided FormatCallback and the args from the given FormatList.
781 func parseFormatStringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parseFormatString().(formatStr string, callback formatStringInterpolatorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatStringInterpolator#, list formatListArgsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatListArgs#, locale string) (string, error) {
782 i := 0
783 argIndex := 0
784 var builtStr stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.Builderscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#
785 for i < len(formatStr) {
786 if formatStr[i] == '%' {
787 if i+1 < len(formatStr) && formatStr[i+1] == '%' {
788 err := builtStr.WriteBytescip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#WriteByte().('%')
789 if err != nil {
790 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("error writing format string: %w", err)
791 }
792 i += 2
793 continue
794 } else {
795 argAny, err := list.Argscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatListArgs#Arg.(int64(argIndex))
796 if err != nil {
797 return "", err
798 }
799 if i+1 >= len(formatStr) {
800 return "", errorsscip-go gomod github.com/golang/go/src go1.23.0 errors/.Newscip-go gomod github.com/golang/go/src go1.23.0 errors/New().("unexpected end of string")
801 }
802 if int64(argIndex) >= list.Sizescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatListArgs#Size.() {
803 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("index %d out of range", argIndex)
804 }
805 numRead, val, refErr := parseAndFormatClausescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parseAndFormatClause().(formatStr[i:], argAny, callback, list, locale)
806 if refErr != nil {
807 return "", refErr
808 }
809 _, err = builtStr.WriteStringscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#WriteString().(val)
810 if err != nil {
811 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("error writing format string: %w", err)
812 }
813 i += numRead
814 argIndex++
815 }
816 } else {
817 err := builtStr.WriteBytescip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#WriteByte().(formatStr[i])
818 if err != nil {
819 return "", fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("error writing format string: %w", err)
820 }
821 i++
822 }
823 }
824 return builtStr.Stringscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#String().(), nil
825 }
826
827 // parseAndFormatClause parses the format clause at the start of the given string with val, and returns
828 // how many characters were consumed and the substituted string form of val, or an error if one occurred.
829 func parseAndFormatClausescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parseAndFormatClause().(formatStr string, val refscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#, callback formatStringInterpolatorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatStringInterpolator#, list formatListArgsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatListArgs#, locale string) (int, string, error) {
830 i := 1
831 read, formatter, err := parseFormattingClausescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parseFormattingClause().(formatStr[i:], callback)
832 i += read
833 if err != nil {
834 return -1, "", newParseFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/newParseFormatError().("could not parse formatting clause", err)
835 }
836
837 valStr, err := formatter(val, locale)
838 if err != nil {
839 return -1, "", newParseFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/newParseFormatError().("error during formatting", err)
840 }
841 return i, valStr, nil
842 }
843
844 func parseFormattingClausescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parseFormattingClause().(formatStr string, callback formatStringInterpolatorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatStringInterpolator#) (int, clauseImplscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/clauseImpl#, error) {
845 i := 0
846 read, precision, err := parsePrecisionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parsePrecision().(formatStr[i:])
847 i += read
848 if err != nil {
849 return -1, nil, fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("error while parsing precision: %w", err)
850 }
851 r := rune(formatStr[i])
852 i++
853 switch r {
854 case 's':
855 return i, callback.Stringscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatStringInterpolator#String., nil
856 case 'd':
857 return i, callback.Decimalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatStringInterpolator#Decimal., nil
858 case 'f':
859 return i, callback.Fixedscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatStringInterpolator#Fixed.(precision), nil
860 case 'e':
861 return i, callback.Scientificscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatStringInterpolator#Scientific.(precision), nil
862 case 'b':
863 return i, callback.Binaryscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatStringInterpolator#Binary., nil
864 case 'x', 'X':
865 return i, callback.Hexscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatStringInterpolator#Hex.(unicodescip-go gomod github.com/golang/go/src go1.23.0 unicode/.IsUpperscip-go gomod github.com/golang/go/src go1.23.0 unicode/IsUpper().(r)), nil
866 case 'o':
867 return i, callback.Octalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/formatStringInterpolator#Octal., nil
868 default:
869 return -1, nil, fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("unrecognized formatting clause \"%c\"", r)
870 }
871 }
872
873 func parsePrecisionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parsePrecision().(formatStr string) (int, *int, error) {
874 i := 0
875 if formatStr[i] != '.' {
876 return i, nil, nil
877 }
878 i++
879 var buffer stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.Builderscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#
880 for {
881 if i >= len(formatStr) {
882 return -1, nil, errorsscip-go gomod github.com/golang/go/src go1.23.0 errors/.Newscip-go gomod github.com/golang/go/src go1.23.0 errors/New().("could not find end of precision specifier")
883 }
884 if !isASCIIDigitscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/isASCIIDigit().(rune(formatStr[i])) {
885 break
886 }
887 buffer.WriteBytescip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#WriteByte().(formatStr[i])
888 i++
889 }
890 precision, err := strconvscip-go gomod github.com/golang/go/src go1.23.0 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.23.0 strconv/Atoi().(buffer.Stringscip-go gomod github.com/golang/go/src go1.23.0 strings/Builder#String().())
891 if err != nil {
892 return -1, nil, fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("error while converting precision to integer: %w", err)
893 }
894 return i, &precision, nil
895 }
896
897 func isASCIIDigitscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/isASCIIDigit().(r rune) bool {
898 return r <= unicodescip-go gomod github.com/golang/go/src go1.23.0 unicode/.MaxASCIIscip-go gomod github.com/golang/go/src go1.23.0 unicode/MaxASCII. && unicodescip-go gomod github.com/golang/go/src go1.23.0 unicode/.IsDigitscip-go gomod github.com/golang/go/src go1.23.0 unicode/IsDigit().(r)
899 }
900
901 type parseFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parseFormatError# struct {
902 msgscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parseFormatError#msg. string
903 wrappedscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parseFormatError#wrapped. error
904 }
905
906 func newParseFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/newParseFormatError().(msg string, wrapped error) error {
907 return parseFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parseFormatError#{msgscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parseFormatError#msg.: msg, wrappedscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parseFormatError#wrapped.: wrapped}
908 }
909
910 // Error implements error.
911 func (e parseFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parseFormatError#) Errorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parseFormatError#Error().() string {
912 return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().("%s: %s", e.msgscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parseFormatError#msg., e.wrappedscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parseFormatError#wrapped..Error())
913 }
914
915 // Is implements errors.Is.
916 func (e parseFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parseFormatError#) Isscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parseFormatError#Is().(target error) bool {
917 return e.Errorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parseFormatError#Error().() == target.Error()
918 }
919
920 // Is implements errors.Unwrap.
921 func (e parseFormatErrorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parseFormatError#) Unwrapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parseFormatError#Unwrap().() error {
922 return e.wrappedscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/parseFormatError#wrapped.
923 }
924
925 const (
926 runtimeIDscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/runtimeID. = int64(-1)
927 )