« blib/lib/Text/Editor/Vip/Buffer/Plugins/FindReplace.pm
↑ Summary
blib/lib/Text/Editor/Vip/Buffer/Selection.pm »
| 1 | |||||||||||||
| 2 | package Text::Editor::Vip::Buffer::Plugins::Display; | ||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 5 | ▶ | use warnings ; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | BEGIN | ||||||||||||
| 7 | 5 | ▶ | { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 5 | ▶ | use Exporter (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 5 | ▶ | use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 5 | $VERSION = 0.01; | |||||||||||
| 12 | 5 | @ISA = qw (Exporter); | |||||||||||
| 13 | 5 | @EXPORT = qw (); | |||||||||||
| 14 | 5 | @EXPORT_OK = qw (); | |||||||||||
| 15 | 5 | %EXPORT_TAGS = (); | |||||||||||
| 16 | } | ||||||||||||
| 17 | |||||||||||||
| 18 | =head1 NAME | ||||||||||||
| 19 | |||||||||||||
| 20 | Text::Editor::Vip::Buffer::Plugins::Display - Text position to display position utilities | ||||||||||||
| 21 | |||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||
| 23 | |||||||||||||
| 24 | use Text::Editor::Vip::Buffer::Dispaly | ||||||||||||
| 25 | |||||||||||||
| 26 | =head1 DESCRIPTION | ||||||||||||
| 27 | |||||||||||||
| 28 | This module let's you define a tab size and convert text and display positions. | ||||||||||||
| 29 | |||||||||||||
| 30 | Tab size is set to 8 by default. | ||||||||||||
| 31 | |||||||||||||
| 32 | =head1 FUNCTIONS | ||||||||||||
| 33 | |||||||||||||
| 34 | =cut | ||||||||||||
| 35 | |||||||||||||
| 36 | #------------------------------------------------------------------------------ | ||||||||||||
| 37 | |||||||||||||
| 38 | sub SetTabSize | ||||||||||||
| 39 | 5 | ▶ | { | ||||||||||
|
Subroutine
SetTabSize: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 40 | |||||||||||||
| 41 | =head2 SetTabSize | ||||||||||||
| 42 | |||||||||||||
| 43 | Sets the tab size used. | ||||||||||||
| 44 | |||||||||||||
| 45 | =cut | ||||||||||||
| 46 | |||||||||||||
| 47 | 5 | $_[0]->{'Text::Editor::Vip::Buffer::Plugins::Display::TAB_SIZE'} = $_[1] ; | |||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | #------------------------------------------------------------------------------- | ||||||||||||
| 51 | |||||||||||||
| 52 | sub GetTabSize | ||||||||||||
| 53 | 64 | ▶ | { | ||||||||||
|
Subroutine
GetTabSize: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 54 | |||||||||||||
| 55 | =head2 GetTabSize | ||||||||||||
| 56 | |||||||||||||
| 57 | Return the tab size | ||||||||||||
| 58 | |||||||||||||
| 59 | =cut | ||||||||||||
| 60 | |||||||||||||
| 61 | 64 | ▶ | return ($_[0]->{'Text::Editor::Vip::Buffer::Plugins::Display::TAB_SIZE'} || 8) ; | ||||||||||
|
Condition100%2/2
$_[0]{'Text::Editor::Vip::Buffer::Plugins::Display::TAB_SIZE'} || 8
MC/DC100%1/1
$_[0]{'Text::Editor::Vip::Buffer::Plugins::Display::TAB_SIZE'} || 8
$_[0]{'Text::Editor::Vip::Buffer::Plugins::Display::TAB_SIZE'}
Truth table100%2/2
A
A= $_[0]{'Text::Editor::Vip::Buffer::Plugins::Display::TAB_SIZE'}
| |||||||||||||
| 62 | } | ||||||||||||
| 63 | |||||||||||||
| 64 | #------------------------------------------------------------------------------- | ||||||||||||
| 65 | |||||||||||||
| 66 | sub GetCharacterPositionInText | ||||||||||||
| 67 | 28 | ▶ | { | ||||||||||
|
Subroutine
GetCharacterPositionInText: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||
| 68 | |||||||||||||
| 69 | =head2 GetCharacterPositionInText | ||||||||||||
| 70 | |||||||||||||
| 71 | Given a display position, returns the the position in text | ||||||||||||
| 72 | |||||||||||||
| 73 | =cut | ||||||||||||
| 74 | |||||||||||||
| 75 | 28 | my ($buffer, $line_index, $position, $line_text) = @_ ; | |||||||||||
| 76 | |||||||||||||
| 77 | 28 | ▶ | $line_text = $buffer->GetLineText($line_index) unless defined $line_text ; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 78 | |||||||||||||
| 79 | 28 | my ($character_position, $display_position) = (0, 0) ; | |||||||||||
| 80 | |||||||||||||
| 81 | 28 | my $tab_size = $buffer->GetTabSize() ; | |||||||||||
| 82 | |||||||||||||
| 83 | 28 | for (split //, $line_text) | |||||||||||
| 84 | { | ||||||||||||
| 85 | 75 | ▶ | if($_ eq "\t") | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 86 | { | ||||||||||||
| 87 | 14 | $display_position += $tab_size ; | |||||||||||
| 88 | } | ||||||||||||
| 89 | else | ||||||||||||
| 90 | { | ||||||||||||
| 91 | 61 | $display_position++ ; | |||||||||||
| 92 | } | ||||||||||||
| 93 | |||||||||||||
| 94 | 75 | ▶ | last if $display_position > $position ; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 95 | 51 | $character_position++ ; | |||||||||||
| 96 | } | ||||||||||||
| 97 | |||||||||||||
| 98 | 28 | ▶ | if($display_position < $position) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 99 | { | ||||||||||||
| 100 | 4 | return(length($line_text) + ($position - $display_position)) ; | |||||||||||
| 101 | } | ||||||||||||
| 102 | else | ||||||||||||
| 103 | { | ||||||||||||
| 104 | 24 | return($character_position) ; | |||||||||||
| 105 | } | ||||||||||||
| 106 | } | ||||||||||||
| 107 | |||||||||||||
| 108 | #------------------------------------------------------------------------------- | ||||||||||||
| 109 | |||||||||||||
| 110 | sub GetCharacterDisplayPosition | ||||||||||||
| 111 | 27 | ▶ | { | ||||||||||
|
Subroutine
GetCharacterDisplayPosition: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 112 | |||||||||||||
| 113 | =head2 GetCharacterDisplayPosition | ||||||||||||
| 114 | |||||||||||||
| 115 | Given a position in the text, returns the the display position | ||||||||||||
| 116 | |||||||||||||
| 117 | =cut | ||||||||||||
| 118 | |||||||||||||
| 119 | 27 | my ($buffer, $line_index, $position, $line_text) = @_ ; | |||||||||||
| 120 | |||||||||||||
| 121 | 27 | $line_text = $buffer->GetLineText($line_index) ; | |||||||||||
| 122 | 27 | ▶ | substr($line_text, $position) = '' if $position < length($line_text) ; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 123 | |||||||||||||
| 124 | 27 | my $tab_size = $buffer->GetTabSize() ; | |||||||||||
| 125 | |||||||||||||
| 126 | 27 | return(($line_text =~ tr/\t/\t/ * ($tab_size - 1)) + $position) ; | |||||||||||
| 127 | } | ||||||||||||
| 128 | |||||||||||||
| 129 | #------------------------------------------------------------------------------- | ||||||||||||
| 130 | |||||||||||||
| 131 | sub GetTabifiedText | ||||||||||||
| 132 | 0 | ▶ | { | ||||||||||
|
Subroutine
GetTabifiedText: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||
| 133 | |||||||||||||
| 134 | # missing doc and tests | ||||||||||||
| 135 | |||||||||||||
| 136 | 0 | my ($buffer, $line_index, $line_text, $tab_size) = @_ ; | |||||||||||
| 137 | |||||||||||||
| 138 | 0 | ▶ | $line_text = $buffer->GetLineText($line_index) unless defined $line_text ; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 139 | |||||||||||||
| 140 | 0 | ▶ | $tab_size = $buffer->GetTabSize() unless defined $tab_size ; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 141 | |||||||||||||
| 142 | 0 | my $tabified_text = '' ; | |||||||||||
| 143 | 0 | my $distance_to_tab = 0 ; | |||||||||||
| 144 | |||||||||||||
| 145 | 0 | for(0 .. length($line_text) - 1) | |||||||||||
| 146 | { | ||||||||||||
| 147 | 0 | ▶ | $distance_to_tab = $tab_size if $distance_to_tab == 0 ; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 148 | |||||||||||||
| 149 | 0 | my $char = substr($line_text, $_, 1) ; | |||||||||||
| 150 | |||||||||||||
| 151 | 0 | ▶ | if("\t" eq $char) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 152 | { | ||||||||||||
| 153 | 0 | $tabified_text .= ' ' x $distance_to_tab ; | |||||||||||
| 154 | 0 | $distance_to_tab = $tab_size ; | |||||||||||
| 155 | } | ||||||||||||
| 156 | else | ||||||||||||
| 157 | { | ||||||||||||
| 158 | 0 | $tabified_text .= $char ; | |||||||||||
| 159 | 0 | $distance_to_tab-- ; | |||||||||||
| 160 | } | ||||||||||||
| 161 | } | ||||||||||||
| 162 | |||||||||||||
| 163 | 0 | return($tabified_text) ; | |||||||||||
| 164 | } | ||||||||||||
| 165 | |||||||||||||
| 166 | #------------------------------------------------------------------------------- | ||||||||||||
| 167 | |||||||||||||
| 168 | 5 | 1 ; | |||||||||||
| 169 | |||||||||||||
| 170 | =head1 AUTHOR | ||||||||||||
| 171 | |||||||||||||
| 172 | Khemir Nadim ibn Hamouda | ||||||||||||
| 173 | CPAN ID: NKH | ||||||||||||
| 174 | mailto:nadim@khemir.net | ||||||||||||
| 175 | http:// no web site | ||||||||||||
| 176 | |||||||||||||
| 177 | =head1 COPYRIGHT | ||||||||||||
| 178 | |||||||||||||
| 179 | This program is free software; you can redistribute | ||||||||||||
| 180 | it and/or modify it under the same terms as Perl itself. | ||||||||||||
| 181 | |||||||||||||
| 182 | The full text of the license can be found in the | ||||||||||||
| 183 | LICENSE file included with this module. | ||||||||||||
| 184 | |||||||||||||
| 185 | =cut | ||||||||||||