18 Aug 2021 11:38:55 UTC
- Distribution: Tickit
- Module version: 0.72
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (11)
- Testers (142 / 45 / 5)
- KwaliteeBus factor: 1
- % Coverage
- License: perl_5
- Perl: v5.14.0
- Activity24 month
- Download (121.95KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version
Tickit::StringPos- store string position counters
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";
Instances in this object class store four position counters that relate to counting strings.
bytesmember 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
codepointscounter by 1.
codepointsmember counts individual Unicode codepoints.
graphemesmember counts whole composed graphical 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
codepointcounter by 2 and the
graphemescounter by 1.
columnsmember 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.
$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.
$bytes = $pos->bytes $codepoints = $pos->codepoints $graphemes = $pos->graphemes $columns = $pos->columns
Return the current value the counters.
Paul Evans <email@example.com>