Documentation for routine
chars assembled from the following types:
multi sub chars(Cool --> Int)multi sub chars(Str --> Int)multi sub chars(str --> int)multi method chars(Str: --> Int)
Returns the number of characters in the string in graphemes. On the JVM, this currently erroneously returns the number of codepoints instead.
chars as payload.
Returns the numbers of characters in the matched string.
Returns the same as
multi sub chars(Cool )multi sub chars(Str )multi sub chars(str --> int)method chars(--> Int)
Coerces the invocant (or in sub form, its argument) to Str, and returns the number of characters in the string. Please note that on the JVM, you currently get codepoints instead of graphemes.
say 'møp'.chars; # OUTPUT: «3␤»say 'ã̷̠̬̊'.chars; # OUTPUT: «1␤»say '👨👩👧👦🏿'.chars; # OUTPUT: «1␤»
If the string is native, the number of chars will be also returned as a native
Graphemes are user visible characters. That is, this is what the user thinks of as a “character”.
Graphemes can contain more than one codepoint. Typically the number of graphemes and codepoints differs when
Extend characters are involved (also known as Combining characters), but there are many other cases when this may happen. Another example is
\c[ZWJ] (Zero-width joiner).
You can check
Grapheme_Cluster_Break property of a character in order to see how it is going to behave:
say ‘ã̷̠̬̊’.uniprops(‘Grapheme_Cluster_Break’); # OUTPUT: «(Other Extend Extend Extend Extend)␤»say ‘👨👩👧👦🏿’.uniprops(‘Grapheme_Cluster_Break’); # OUTPUT: «(E_Base_GAZ ZWJ E_Base_GAZ ZWJ E_Base_GAZ ZWJ E_Base_GAZ E_Modifier)␤»