Celixir.Ext.Strings (Celixir v0.2.0)

Copy Markdown View Source

Strings extension for CEL — mirrors ext.Strings() from cel-go.

Provides extended string functions. Most string methods (charAt, indexOf, substring, split, join, lowerAscii, upperAscii, trim, replace, reverse, lastIndexOf) are available as built-ins. This module adds explicit registration and the strings.quote global function.

Usage

env = Celixir.Environment.new() |> Celixir.Ext.Strings.register()
Celixir.eval!(~s|strings.quote("hello\nworld")|, env)
# => ""hello\\nworld""

Functions (method style, on strings)

  • str.charAt(int) — character at index
  • str.indexOf(string) / str.indexOf(string, int) — first occurrence index
  • str.lastIndexOf(string) / str.lastIndexOf(string, int) — last occurrence
  • str.substring(int) / str.substring(int, int) — substring
  • str.split(string) / str.split(string, int) — split into list
  • str.join() / str.join(string) — join list of strings
  • str.lowerAscii() — ASCII lowercase
  • str.upperAscii() — ASCII uppercase
  • str.trim() — trim leading/trailing whitespace
  • str.replace(old, new) / str.replace(old, new, int) — replace substrings
  • str.reverse() — reverse characters
  • strings.quote(string) — safely quote a string for printing

Summary

Functions

Registers string extension functions into the given environment.

Functions

quote_string(s)

register(env \\ Environment.new())

Registers string extension functions into the given environment.