chars
ErrorsCollection

chars

Synthesised documentation from type/Blob type/Match type/Cool type/Str

From type/Blob

See Original text in context

method chars(Blob:D:)

Throws X::Buf::AsStr with chars as payload.

From type/Match

See Original text in context

method chars()

Returns the numbers of characters in the matched string or 0 if there's been no match.

Returns the same as .Str.chars.

From type/Cool

See Original text in context

multi sub chars(Cool $x)
multi sub chars(Str:D $x)
multi sub chars(str $x --> int)
method chars(--> Int:D)

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 int.

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 Prepend or 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)␤»

You can read more about graphemes in the Unicode Standard, which Raku tightly follows, using a method called NFG, normal form graphemes for efficiently representing them.

From type/Str

See Original text in context

multi sub    chars(Cool  $x --> Int:D)
multi sub    chars(Str:D $x --> Int:D)
multi sub    chars(str   $x --> int)
multi method chars(Str:D:   --> Int:D)

Returns the number of characters in the string in graphemes. On the JVM, this currently erroneously returns the number of codepoints instead.