CompileOptions implements the cel.Library interface method.
()
| 133 | |
| 134 | // CompileOptions implements the cel.Library interface method. |
| 135 | func (r *regexLib) CompileOptions() []cel.EnvOption { |
| 136 | optionalTypesEnabled := func(env *cel.Env) (*cel.Env, error) { |
| 137 | if !env.HasLibrary("cel.lib.optional") { |
| 138 | return nil, errors.New("regex library requires the optional library") |
| 139 | } |
| 140 | return env, nil |
| 141 | } |
| 142 | opts := []cel.EnvOption{ |
| 143 | cel.Function(regexExtract, |
| 144 | cel.Overload("regex_extract_string_string", []*cel.Type{cel.StringType, cel.StringType}, cel.OptionalType(cel.StringType), |
| 145 | cel.BinaryBinding(extract))), |
| 146 | |
| 147 | cel.Function(regexExtractAll, |
| 148 | cel.Overload("regex_extractAll_string_string", []*cel.Type{cel.StringType, cel.StringType}, cel.ListType(cel.StringType), |
| 149 | cel.BinaryBinding(extractAll))), |
| 150 | |
| 151 | cel.Function(regexReplace, |
| 152 | cel.Overload("regex_replace_string_string_string", []*cel.Type{cel.StringType, cel.StringType, cel.StringType}, cel.StringType, |
| 153 | cel.FunctionBinding(regReplace)), |
| 154 | cel.Overload("regex_replace_string_string_string_int", []*cel.Type{cel.StringType, cel.StringType, cel.StringType, cel.IntType}, cel.StringType, |
| 155 | cel.FunctionBinding((regReplaceN))), |
| 156 | ), |
| 157 | cel.CostEstimatorOptions( |
| 158 | checker.OverloadCostEstimate("regex_extract_string_string", estimateExtractCost()), |
| 159 | checker.OverloadCostEstimate("regex_extractAll_string_string", estimateExtractAllCost()), |
| 160 | checker.OverloadCostEstimate("regex_replace_string_string_string", estimateReplaceCost()), |
| 161 | checker.OverloadCostEstimate("regex_replace_string_string_string_int", estimateReplaceCost()), |
| 162 | ), |
| 163 | cel.EnvOption(optionalTypesEnabled), |
| 164 | } |
| 165 | return opts |
| 166 | } |
| 167 | |
| 168 | // ProgramOptions implements the cel.Library interface method |
| 169 | func (r *regexLib) ProgramOptions() []cel.ProgramOption { |
nothing calls this directly
no test coverage detected