| 1 | package TUI::Editors::Util; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Utility functions for editor buffers | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 15 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 15 | our $VERSION = '2.000003'; | |||||||||||||||||||||||||||
| 9 | 15 | $VERSION =~ tr/_//d; | |||||||||||||||||||||||||||
| 10 | 15 | our $AUTHORITY = 'cpan:BRICKPOOL'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 15 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 15 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 14 | countLines | ||||||||||||||||||||||||||||
| 15 | iScan | ||||||||||||||||||||||||||||
| 16 | scan | ||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||
| 18 | 15 | our %EXPORT_TAGS = ( | |||||||||||||||||||||||||||
| 19 | all => \@EXPORT_OK, | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 15 | ▶ | use TUI::toolkit qw( signature ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 15 | ▶ | use TUI::toolkit::Types qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | Maybe | ||||||||||||||||||||||||||||
| 25 | PositiveOrZeroInt | ||||||||||||||||||||||||||||
| 26 | Str | ||||||||||||||||||||||||||||
| 27 | 15 | ); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 15 | ▶ | use TUI::Editors::Const qw( sfSearchFailed ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 4 | ▶ | sub countLines { # $count ($buf, |$count) | ||||||||||||||||||||||||||
|
Subroutine
countLines: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | 4 | state $sig = signature( | |||||||||||||||||||||||||||
| 33 | pos => [ | ||||||||||||||||||||||||||||
| 34 | Str, | ||||||||||||||||||||||||||||
| 35 | PositiveOrZeroInt, { optional => 1 }, | ||||||||||||||||||||||||||||
| 36 | ], | ||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | 4 | my ( $buf, $count ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 4 | ▶ | return 0 unless length $buf; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 3 | ▶ | $buf = substr( $buf, 0, $count ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $count and $count < length $buf
MC/DC50%1/2
defined $count and $count < length $buf
defined $count
$count < length $buf
Truth table66%2/3
A and B
A= defined $countB= $count < length $buf
| |||||||||||||||||||||||||||||
| 43 | if defined $count && $count < length $buf; | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 3 | my $lines = () = $buf =~ /\R/g; | |||||||||||||||||||||||||||
| 46 | 3 | return $lines; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 6 | ▶ | sub iScan { # $pos ($block, $size, $str) | ||||||||||||||||||||||||||
|
Subroutine
iScan: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | 6 | state $sig = signature( | |||||||||||||||||||||||||||
| 51 | pos => [ | ||||||||||||||||||||||||||||
| 52 | Str, | ||||||||||||||||||||||||||||
| 53 | PositiveOrZeroInt, | ||||||||||||||||||||||||||||
| 54 | Str, | ||||||||||||||||||||||||||||
| 55 | ], | ||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||
| 57 | 6 | my ( $block, $size, $str ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 6 | ▶ | return sfSearchFailed unless length $str; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 5 | ▶ | $block = substr( $block, 0, $size ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | if $size < length $block; | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 5 | ▶ | return $-[0] if $block =~ /\Q$str\E/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 1 | return sfSearchFailed; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 5 | ▶ | sub scan { # $pos ($block, $size, $str) | ||||||||||||||||||||||||||
|
Subroutine
scan: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 5 | state $sig = signature( | |||||||||||||||||||||||||||
| 70 | pos => [ | ||||||||||||||||||||||||||||
| 71 | Str, | ||||||||||||||||||||||||||||
| 72 | PositiveOrZeroInt, | ||||||||||||||||||||||||||||
| 73 | Str, | ||||||||||||||||||||||||||||
| 74 | ], | ||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||
| 76 | 5 | my ( $block, $size, $str ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 5 | ▶ | return sfSearchFailed unless length $str; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 4 | ▶ | $block = substr( $block, 0, $size ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | if $size < length $block; | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 4 | my $pos = index( $block, $str ); | |||||||||||||||||||||||||||
| 84 | 4 | ▶ | return $pos >= 0 ? $pos : sfSearchFailed; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 15 | 1 | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | __END__ | ||||||||||||||||||||||||||||