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

Method CompileOptions

ext/strings.go:392–620  ·  view source on GitHub ↗

CompileOptions implements the Library interface method.

()

Source from the content-addressed store, hash-verified

390
391// CompileOptions implements the Library interface method.
392func (lib *stringLib) CompileOptions() []cel.EnvOption {
393 formatLocale := "en_US"
394 if lib.version < 4 && lib.locale != "" {
395 // ensure locale is properly-formed if set
396 _, err := language.Parse(lib.locale)
397 if err != nil {
398 return []cel.EnvOption{
399 func(e *cel.Env) (*cel.Env, error) {
400 return nil, fmt.Errorf("failed to parse locale: %w", err)
401 },
402 }
403 }
404 formatLocale = lib.locale
405 }
406
407 opts := []cel.EnvOption{
408 cel.Function("charAt",
409 cel.MemberOverload("string_char_at_int", []*cel.Type{cel.StringType, cel.IntType}, cel.StringType,
410 cel.BinaryBinding(func(str, ind ref.Val) ref.Val {
411 s := str.(types.String)
412 i := ind.(types.Int)
413 return stringOrError(charAt(string(s), int64(i)))
414 }))),
415 cel.Function("indexOf",
416 cel.MemberOverload("string_index_of_string", []*cel.Type{cel.StringType, cel.StringType}, cel.IntType,
417 cel.BinaryBinding(func(str, substr ref.Val) ref.Val {
418 s := str.(types.String)
419 sub := substr.(types.String)
420 return intOrError(indexOf(string(s), string(sub)))
421 })),
422 cel.MemberOverload("string_index_of_string_int", []*cel.Type{cel.StringType, cel.StringType, cel.IntType}, cel.IntType,
423 cel.FunctionBinding(func(args ...ref.Val) ref.Val {
424 s := args[0].(types.String)
425 sub := args[1].(types.String)
426 offset := args[2].(types.Int)
427 return intOrError(indexOfOffset(string(s), string(sub), int64(offset)))
428 }))),
429 cel.Function("lastIndexOf",
430 cel.MemberOverload("string_last_index_of_string", []*cel.Type{cel.StringType, cel.StringType}, cel.IntType,
431 cel.BinaryBinding(func(str, substr ref.Val) ref.Val {
432 s := str.(types.String)
433 sub := substr.(types.String)
434 return intOrError(lastIndexOf(string(s), string(sub)))
435 })),
436 cel.MemberOverload("string_last_index_of_string_int", []*cel.Type{cel.StringType, cel.StringType, cel.IntType}, cel.IntType,
437 cel.FunctionBinding(func(args ...ref.Val) ref.Val {
438 s := args[0].(types.String)
439 sub := args[1].(types.String)
440 offset := args[2].(types.Int)
441 return intOrError(lastIndexOfOffset(string(s), string(sub), int64(offset)))
442 }))),
443 cel.Function("lowerAscii",
444 cel.MemberOverload("string_lower_ascii", []*cel.Type{cel.StringType}, cel.StringType,
445 cel.UnaryBinding(func(str ref.Val) ref.Val {
446 s := str.(types.String)
447 return stringOrError(lowerASCII(string(s)))
448 }))),
449 cel.Function("replace",

Callers

nothing calls this directly

Calls 15

FunctionFunction · 0.92
MemberOverloadFunction · 0.92
BinaryBindingFunction · 0.92
FunctionBindingFunction · 0.92
UnaryBindingFunction · 0.92
OverloadFunction · 0.92
WrapErrFunction · 0.92
ASTValidatorsFunction · 0.92
OverloadCostEstimateFunction · 0.92
CostEstimatorOptionsFunction · 0.92
stringOrErrorFunction · 0.85
charAtFunction · 0.85

Tested by

no test coverage detected