Unicode::GCString(3)
π NAME π
okay so this is Unicode::GCString(3) from the User Contributed Perl Documentation, and the official name is: Unicode::GCString - String as Sequence of UAX #29 Grapheme Clusters. That's the whole glow-up: a string, but as a sequence of UAX #29 grapheme clusters. slay β¨
β¨ SYNOPSIS β¨
use Unicode::GCString;
$gcstring = Unicode::GCString->new($string);
That's the entire synopsis, no cap. π
πΈ DESCRIPTION πΈ
Unicode::GCString treats a Unicode string as a sequence of extended grapheme clusters defined by Unicode Standard Annex #29 [UAX #29].
A grapheme cluster is a sequence of Unicode character(s) that consists of one grapheme base and optional grapheme extender and/or βprependβ character. It's close to what people consider as a character. Yes, that's lowkey the whole point. π
π«Ά Public Interface π«Ά
π Constructors π
new (STRING, [KEY => VALUE, ...])/new (STRING, [LINEBREAK])β constructor. Create new grapheme cluster string (Unicode::GCStringobject) from Unicode string STRING. About optionalKEY => VALUEpairs, see the Options section inUnicode::LineBreak. On second form,Unicode::LineBreakobject LINEBREAK controls breaking features. Note: The first form was introduced by release2012.10.copyβ copy constructor. Create a copy of grapheme cluster string. Next position of new string is set at beginning. π«Ά
π Sizes π
charsβ instance method. Returns number of Unicode characters grapheme cluster string includes, i.e. length as Unicode string.columnsβ instance method. Returns total number of columns of grapheme clusters defined by built-in character database. For more details see DESCRIPTION inUnicode::LineBreak.lengthβ instance method. Returns number of grapheme clusters contained in grapheme cluster string.
π Operations as String π
as_string/"""OBJECT"""β instance method. Convert grapheme cluster string to Unicode string explicitly.cmp (STRING)/STRING "cmp" STRINGβ instance method. Compare strings. There are no oddities. One of each STRING may be Unicode string.concat (STRING)/STRING "." STRINGβ instance method. Concatenate STRINGs. One of each STRING may be Unicode string. Note that number of columns (seecolumns()) or grapheme clusters (seelength()) of resulting string is not always equal to sum of both strings. Next position of new string is that set on the left value.join ([STRING, ...])β instance method. Join STRINGs inserting grapheme cluster string. Any of STRINGs may be Unicode string.substr (OFFSET, [LENGTH, [REPLACEMENT]])β instance method. Returns substring of grapheme cluster string. OFFSET and LENGTH are based on grapheme clusters. If REPLACEMENT is specified, substring is replaced by it. REPLACEMENT may be Unicode string. Note: This method cannot return the lvalue, unlike built-insubstr().
π¦ Operations as Sequence of Grapheme Clusters π¦
as_array/"@{OBJECT}"/as_arrayrefβ instance method. Convert grapheme cluster string to an array of grapheme clusters.eosβ instance method. Test if current position is at end of grapheme cluster string.item ([OFFSET])β instance method. Returns OFFSET-th grapheme cluster. If OFFSET was not specified, returns next grapheme cluster.next/"<"OBJECT">"β instance method, iterative. Returns next grapheme cluster and increment next position.pos ([OFFSET])β instance method. If optional OFFSET is specified, set next position by it. Returns next position of grapheme cluster string.
π Miscelaneous π
lbcβ instance method. Returns Line Breaking Class (SeeUnicode::LineBreak) of the first character of first grapheme cluster.lbcextβ instance method. Returns Line Breaking Class (SeeUnicode::LineBreak) of the last grapheme extender of last grapheme cluster. If there are no grapheme extenders or its class isCM, value of last grapheme base will be returned.
π CAVEATS π
- The grapheme cluster should not be referred to as "grapheme" even though Larry does. (iconic behavior, honestly)
- On Perl around
5.10.1, implicit conversion fromUnicode::GCStringobject to Unicode string sometimes letutf8_mg_pos_cache_updatecache be confused. For example, instead of doing:
$sub = substr($gcstring, $i, $j);
do:
$sub = substr("$gcstring", $i, $j);
$sub = substr($gcstring->as_string, $i, $j);
- This module implements default algorithm for determining grapheme cluster boundaries. Tailoring mechanism has not been supported yet.
β VERSION β
Consult $VERSION variable.
π Incompatible Changes π
Release 2013.10
- The
new()method can take non-Unicode string argument. In this case it will be decoded byiso-8859-1(Latin 1) character set. That method of former releases would die with non-Unicode inputs.
π₯ SEE ALSO π₯
[UAX #29] Mark Davis (ed.) (2009-2013). Unicode Standard Annex #29: Unicode Text Segmentation, Revisions 15-23. <http://www.unicode.org/reports/tr29/>.
π AUTHOR π
Hatuka*nezumi - IKEDA Soji <hatuka(at)nezumi.nu>
π COPYRIGHT π
Copyright (C) 2009-2013 Hatuka*nezumi - IKEDA Soji.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
β¨ and that's the whole iconic Unicode::GCString(3) page, bestie β source/version perl v5.42.0, dated 2018-12-29, mwah πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Unicode-LineBreak 2019.001-160000.2.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Unicode-LineBreak 2019.001-160000.2.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Unicode-LineBreak 2019.001-160000.2.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Unicode-LineBreak 2019.001-160000.2.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms