Returns the length of a string.
Without a unit argument, the length is counted in codepoints, unless the
backwards-compatibility key config :ash, :default_string_length_count is set to
:mixed, in which case it is counted in graphemes (see the backwards compatibility
guide). An optional second argument selects a unit explicitly:
:graphemes- counts unicode graphemes, i.eString.length/1.:codepoints- counts unicode codepoints. This matches how most SQL data layers count the length of a string.:bytes- counts bytes, i.ebyte_size/1.
A single grapheme may be made up of an unbounded number of codepoints
(e.g. a base character followed by many combining marks), so counting graphemes
places no effective bound on the size of a value. Use :codepoints or :bytes
when the length is being used as a limit.
Data layers cannot count graphemes, so :graphemes is only supported where the
expression is evaluated in Elixir. Note that string_length/1 is translated to the
data layer's native length function, which counts codepoints, regardless of the
configured default.
string_length(name)
string_length(name, :bytes)
Summary
Functions
Callback implementation for Ash.Query.Function.args/0.
The supported units for counting string length.
Counts the length of a string in the given unit.
Functions
Callback implementation for Ash.Query.Function.args/0.
The supported units for counting string length.
@spec string_length(String.t() | Ash.CiString.t(), :graphemes | :codepoints | :bytes) :: non_neg_integer()
Counts the length of a string in the given unit.
See the module documentation for the supported units.