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