| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Text::Editor::Vip::Buffer::List; |
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
22868
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
32
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings ; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
25
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use Carp qw(cluck) ; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
88
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
BEGIN |
|
9
|
|
|
|
|
|
|
{ |
|
10
|
1
|
|
|
1
|
|
6
|
use Exporter (); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
26
|
|
|
11
|
1
|
|
|
1
|
|
5
|
use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
113
|
|
|
12
|
1
|
|
|
1
|
|
1
|
$VERSION = 0.01; |
|
13
|
1
|
|
|
|
|
13
|
@ISA = qw (Exporter); |
|
14
|
1
|
|
|
|
|
2
|
@EXPORT = qw (); |
|
15
|
1
|
|
|
|
|
7
|
@EXPORT_OK = qw (); |
|
16
|
1
|
|
|
|
|
621
|
%EXPORT_TAGS = (); |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 NAME |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Text::Editor::Vip::Buffer::List - lines container |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
use Text::Editor::Vip::Buffer::List |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Container class used by B to hold the buffers text. Elements aer accessed by index. |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 MEMBER FUNCTIONS |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub new |
|
38
|
|
|
|
|
|
|
{ |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 new |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Create an empty container. Takes no arguments. |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
|
45
|
|
|
|
|
|
|
|
|
46
|
1
|
|
|
1
|
1
|
16
|
my $invocant = shift ; |
|
47
|
1
|
|
33
|
|
|
10
|
my $class = ref($invocant) || $invocant ; |
|
48
|
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
7
|
return( bless [], $class ); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub GetNumberOfNodes |
|
55
|
|
|
|
|
|
|
{ |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 GetNumberOfNodes |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Returns the number of contained elements. |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
|
62
|
|
|
|
|
|
|
|
|
63
|
6
|
|
|
6
|
1
|
10
|
return(scalar(@{$_[0]})) ; |
|
|
6
|
|
|
|
|
31
|
|
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub Push |
|
69
|
|
|
|
|
|
|
{ |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 Push |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Adds an element at the end of the the container. Returns it's index. |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
|
76
|
|
|
|
|
|
|
|
|
77
|
2
|
|
|
2
|
1
|
2249
|
push @{$_[0]}, $_[1] ; |
|
|
2
|
|
|
|
|
13
|
|
|
78
|
2
|
|
|
|
|
4
|
return($#{$_[0]}) ; |
|
|
2
|
|
|
|
|
8
|
|
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub GetNodeData |
|
84
|
|
|
|
|
|
|
{ |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 GetNodeData |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Returns an element or undef if the element doesn't exist. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
$list = new Text::Editor::Vip::Buffer::List() ; |
|
91
|
|
|
|
|
|
|
$list->Push(['some_element']) ; |
|
92
|
|
|
|
|
|
|
my $element = $list->GetNodeData(0) ; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
|
95
|
|
|
|
|
|
|
|
|
96
|
2
|
|
|
2
|
1
|
518
|
my $this = shift ; |
|
97
|
2
|
|
|
|
|
3
|
my $a_node_index = shift ; |
|
98
|
|
|
|
|
|
|
|
|
99
|
2
|
50
|
33
|
|
|
14
|
if(0 <= $a_node_index && $a_node_index < $this->GetNumberOfNodes()) |
|
100
|
|
|
|
|
|
|
{ |
|
101
|
2
|
|
|
|
|
10
|
return($this->[$a_node_index]) ; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
else |
|
104
|
|
|
|
|
|
|
{ |
|
105
|
0
|
|
|
|
|
0
|
cluck("$a_node_index is an invalide node index") ; |
|
106
|
0
|
|
|
|
|
0
|
return(undef) ; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub SetNodeData |
|
113
|
|
|
|
|
|
|
{ |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 SetNodeData |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Sets the element at the given index. The element must exist. |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
my $index = 0 ; |
|
120
|
|
|
|
|
|
|
my $element = [] ; |
|
121
|
|
|
|
|
|
|
$list->SetNodeData($index, $element) ; |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
|
124
|
|
|
|
|
|
|
|
|
125
|
0
|
|
|
0
|
1
|
0
|
my $this = shift ; |
|
126
|
0
|
|
|
|
|
0
|
my $a_node_index = shift ; |
|
127
|
0
|
|
|
|
|
0
|
my $a_node_data = shift ; |
|
128
|
|
|
|
|
|
|
|
|
129
|
0
|
0
|
0
|
|
|
0
|
if(0 <= $a_node_index && $a_node_index < $this->GetNumberOfNodes()) |
|
130
|
|
|
|
|
|
|
{ |
|
131
|
0
|
|
|
|
|
0
|
$this->[$a_node_index] = $a_node_data ; |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
else |
|
134
|
|
|
|
|
|
|
{ |
|
135
|
0
|
|
|
|
|
0
|
cluck("$a_node_index is an invalide node index") ; |
|
136
|
0
|
|
|
|
|
0
|
return(undef) ; |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub DeleteNode |
|
144
|
|
|
|
|
|
|
{ |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 DeleteNode |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Removes the lement at the given index. all elements after the given index are shifted up in the list. The element |
|
149
|
|
|
|
|
|
|
must exist. |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
$list->DeleteNode($index) ; |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=cut |
|
154
|
|
|
|
|
|
|
|
|
155
|
0
|
|
|
0
|
1
|
0
|
my $this = shift ; |
|
156
|
0
|
|
|
|
|
0
|
my $a_node_index = shift ; |
|
157
|
|
|
|
|
|
|
|
|
158
|
0
|
0
|
|
|
|
0
|
if(0 != $this->GetNumberOfNodes()) |
|
159
|
|
|
|
|
|
|
{ |
|
160
|
0
|
0
|
0
|
|
|
0
|
if(0 <= $a_node_index && $a_node_index < $this->GetNumberOfNodes()) |
|
161
|
|
|
|
|
|
|
{ |
|
162
|
0
|
|
|
|
|
0
|
splice |
|
163
|
|
|
|
|
|
|
( |
|
164
|
0
|
|
|
|
|
0
|
@{$this} |
|
165
|
|
|
|
|
|
|
, $a_node_index |
|
166
|
|
|
|
|
|
|
, 1 |
|
167
|
|
|
|
|
|
|
) ; |
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
else |
|
170
|
|
|
|
|
|
|
{ |
|
171
|
0
|
|
|
|
|
0
|
cluck("$a_node_index is an invalide node index") ; |
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
else |
|
175
|
|
|
|
|
|
|
{ |
|
176
|
0
|
|
|
|
|
0
|
cluck('List is empty, nothing to delete !!') ; |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
} |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub InsertAfter |
|
183
|
|
|
|
|
|
|
{ |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head2 InsertAfter |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Creates and inserts an element in the list after the given index. The element at the given index must exist. |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
$list->InsertAfter($index, $element_data) ; |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=cut |
|
192
|
|
|
|
|
|
|
|
|
193
|
1
|
|
|
1
|
1
|
1139
|
my $this = shift ; |
|
194
|
1
|
|
|
|
|
2
|
my $a_node_index = shift ; |
|
195
|
1
|
|
|
|
|
3
|
my $a_node_data = shift ; |
|
196
|
|
|
|
|
|
|
|
|
197
|
1
|
50
|
|
|
|
4
|
if(0 != $this->GetNumberOfNodes()) |
|
198
|
|
|
|
|
|
|
{ |
|
199
|
1
|
50
|
33
|
|
|
12
|
if(0 <= $a_node_index && $a_node_index < $this->GetNumberOfNodes()) |
|
200
|
|
|
|
|
|
|
{ |
|
201
|
1
|
|
|
|
|
4
|
splice |
|
202
|
|
|
|
|
|
|
( |
|
203
|
1
|
|
|
|
|
2
|
@{$this} |
|
204
|
|
|
|
|
|
|
, $a_node_index + 1 |
|
205
|
|
|
|
|
|
|
, 0 |
|
206
|
|
|
|
|
|
|
, $a_node_data |
|
207
|
|
|
|
|
|
|
) ; |
|
208
|
|
|
|
|
|
|
|
|
209
|
1
|
|
|
|
|
4
|
return($a_node_index + 1) ; |
|
210
|
|
|
|
|
|
|
} |
|
211
|
|
|
|
|
|
|
else |
|
212
|
|
|
|
|
|
|
{ |
|
213
|
0
|
|
|
|
|
0
|
cluck("$a_node_index is an invalide node index") ; |
|
214
|
|
|
|
|
|
|
} |
|
215
|
|
|
|
|
|
|
} |
|
216
|
|
|
|
|
|
|
else |
|
217
|
|
|
|
|
|
|
{ |
|
218
|
0
|
|
|
|
|
0
|
cluck('List is empty !!') ; |
|
219
|
|
|
|
|
|
|
} |
|
220
|
|
|
|
|
|
|
} |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub InsertBefore |
|
225
|
|
|
|
|
|
|
{ |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head2 InsertBefore |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Creates and inserts an element in the list before the given index. The element at the given index must exist. |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
$list->InsertBefore($index, $element_data) ; |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=cut |
|
234
|
|
|
|
|
|
|
|
|
235
|
1
|
|
|
1
|
1
|
4
|
my ($this, $a_node_index, $a_node_data) = @_ ; |
|
236
|
|
|
|
|
|
|
|
|
237
|
1
|
50
|
|
|
|
3
|
if(0 != $this->GetNumberOfNodes()) |
|
238
|
|
|
|
|
|
|
{ |
|
239
|
1
|
50
|
33
|
|
|
9
|
if(0 <= $a_node_index && $a_node_index < $this->GetNumberOfNodes()) |
|
240
|
|
|
|
|
|
|
{ |
|
241
|
1
|
50
|
|
|
|
4
|
if(0 == $a_node_index) |
|
242
|
|
|
|
|
|
|
{ |
|
243
|
0
|
|
|
|
|
0
|
unshift @{$this}, $a_node_data ; |
|
|
0
|
|
|
|
|
0
|
|
|
244
|
|
|
|
|
|
|
} |
|
245
|
|
|
|
|
|
|
else |
|
246
|
|
|
|
|
|
|
{ |
|
247
|
1
|
|
|
|
|
3
|
splice |
|
248
|
|
|
|
|
|
|
( |
|
249
|
1
|
|
|
|
|
3
|
@{$this} |
|
250
|
|
|
|
|
|
|
, $a_node_index |
|
251
|
|
|
|
|
|
|
, 0 |
|
252
|
|
|
|
|
|
|
, $a_node_data |
|
253
|
|
|
|
|
|
|
) ; |
|
254
|
|
|
|
|
|
|
|
|
255
|
1
|
|
|
|
|
4
|
return($a_node_index) ; |
|
256
|
|
|
|
|
|
|
} |
|
257
|
|
|
|
|
|
|
} |
|
258
|
|
|
|
|
|
|
else |
|
259
|
|
|
|
|
|
|
{ |
|
260
|
0
|
|
|
|
|
|
cluck("$a_node_index is an invalide node index") ; |
|
261
|
|
|
|
|
|
|
} |
|
262
|
|
|
|
|
|
|
} |
|
263
|
|
|
|
|
|
|
else |
|
264
|
|
|
|
|
|
|
{ |
|
265
|
0
|
|
|
|
|
|
cluck('List is empty !!') ; |
|
266
|
|
|
|
|
|
|
} |
|
267
|
|
|
|
|
|
|
} |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
1; |
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=head1 AUTHOR |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
Khemir Nadim ibn Hamouda |
|
276
|
|
|
|
|
|
|
CPAN ID: NKH |
|
277
|
|
|
|
|
|
|
mailto:nadim@khemir.net |
|
278
|
|
|
|
|
|
|
http:// no web site |
|
279
|
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
281
|
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
This program is free software; you can redistribute |
|
283
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
The full text of the license can be found in the |
|
286
|
|
|
|
|
|
|
LICENSE file included with this module. |
|
287
|
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=cut |