NAME
Tickit::StringPos
- store string position counters
SYNOPSIS
use Tickit::StringPos;
use Tickit::Utils qw( string_count );
my $pos = Tickit::StringPos->zero;
string_count( "Here is a message", $pos );
print "The message consumes ", $pos->columns, " columns\n";
DESCRIPTION
Instances in this object class store four position counters that relate to counting strings.
The bytes
member counts UTF-8 bytes which encode individual codepoints. For example the Unicode character U+00E9 is encoded by two bytes 0xc3, 0xa9; it would increment the bytes counter by 2 and the codepoints
counter by 1.
The codepoints
member counts individual Unicode codepoints.
The graphemes
member counts whole composed grahical clusters of codepoints, where combining accents which count as individual codepoints do not count as separate graphemes. For example, the codepoint sequence U+0065 U+0301 would increment the codepoint
counter by 2 and the graphemes
counter by 1.
The columns
member counts the number of screen columns consumed by the graphemes. Most graphemes consume only 1 column, but some are defined in Unicode to consume 2.
Instances are also used to store count limits, where any memeber may be set to -1 to indicate no limit in that counter.
CONSTRUCTORS
$pos = Tickit::StringPos->zero
Returns a new instance with all counters set to zero.
$pos = Tickit::StringPos->limit_bytes( $bytes )
$pos = Tickit::StringPos->limit_codepoints( $codepoints )
$pos = Tickit::StringPos->limit_graphemes( $graphemes )
$pos = Tickit::StringPos->limit_columns( $columns )
Return a new instance with one counter set to the given limit and the other three counters set to -1.
METHODS
$bytes = $pos->bytes
$codepoints = $pos->codepoints
$graphemes = $pos->graphemes
$columns = $pos->columns
Return the current value the counters.
AUTHOR
Paul Evans <leonerd@leonerd.org.uk>