logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

"Tickit::StringPos" - store string position counters

Author

       Paul Evans <leonerd@leonerd.org.uk>

perl v5.40.0                                       2024-10-20                             Tickit::StringPos(3pm)

Constructors

zero
          $pos = Tickit::StringPos->zero

       Returns a new instance with all counters set to zero.

   limit_byteslimit_codepointslimit_graphemeslimit_columns
          $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.

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 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 "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 member may be set to -1 to indicate no limit in
       that counter.

Methods

bytescodepointsgraphemescolumns
          $bytes = $pos->bytes

          $codepoints = $pos->codepoints

          $graphemes = $pos->graphemes

          $columns = $pos->columns

       Return the current value the counters.

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";

See Also