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

Method CompileOptions

ext/strings.go:389–616  ·  view source on GitHub ↗

CompileOptions implements the Library interface method.

()

Source from the content-addressed store, hash-verified

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

Tested by

no test coverage detected