1Tickit::StringPos(3pm)User Contributed Perl DocumentationTickit::StringPos(3pm)
2
3
4
6 "Tickit::StringPos" - store string position counters
7
9 use Tickit::StringPos;
10 use Tickit::Utils qw( string_count );
11
12 my $pos = Tickit::StringPos->zero;
13 string_count( "Here is a message", $pos );
14
15 print "The message consumes ", $pos->columns, " columns\n";
16
18 Instances in this object class store four position counters that relate
19 to counting strings.
20
21 The "bytes" member counts UTF-8 bytes which encode individual
22 codepoints. For example the Unicode character U+00E9 is encoded by two
23 bytes 0xc3, 0xa9; it would increment the bytes counter by 2 and the
24 "codepoints" counter by 1.
25
26 The "codepoints" member counts individual Unicode codepoints.
27
28 The "graphemes" member counts whole composed graphical clusters of
29 codepoints, where combining accents which count as individual
30 codepoints do not count as separate graphemes. For example, the
31 codepoint sequence U+0065 U+0301 would increment the "codepoint"
32 counter by 2 and the "graphemes" counter by 1.
33
34 The "columns" member counts the number of screen columns consumed by
35 the graphemes. Most graphemes consume only 1 column, but some are
36 defined in Unicode to consume 2.
37
38 Instances are also used to store count limits, where any memeber may be
39 set to -1 to indicate no limit in that counter.
40
42 zero
43 $pos = Tickit::StringPos->zero
44
45 Returns a new instance with all counters set to zero.
46
47 limit_bytes
48 limit_codepoints
49 limit_graphemes
50 limit_columns
51 $pos = Tickit::StringPos->limit_bytes( $bytes )
52
53 $pos = Tickit::StringPos->limit_codepoints( $codepoints )
54
55 $pos = Tickit::StringPos->limit_graphemes( $graphemes )
56
57 $pos = Tickit::StringPos->limit_columns( $columns )
58
59 Return a new instance with one counter set to the given limit and the
60 other three counters set to -1.
61
63 bytes
64 codepoints
65 graphemes
66 columns
67 $bytes = $pos->bytes
68
69 $codepoints = $pos->codepoints
70
71 $graphemes = $pos->graphemes
72
73 $columns = $pos->columns
74
75 Return the current value the counters.
76
78 Paul Evans <leonerd@leonerd.org.uk>
79
80
81
82perl v5.38.0 2023-07-21 Tickit::StringPos(3pm)