perl5.000 patch.0i: fix glaring mistakes in patches a-h
[p5sagit/p5-mst-13.2.git] / lib / Text / Tabs.pm
CommitLineData
a0d0e21e 1#
2# expand and unexpand tabs as per the unix expand and
3# unexpand programs.
4#
5# expand and unexpand operate on arrays of lines. Do not
6# feed strings that contain newlines to them.
7#
8# David Muir Sharnoff <muir@idiom.com>
9#
10
75f92628 11package Text::Tabs;
a0d0e21e 12
13require Exporter;
14
15@ISA = (Exporter);
16@EXPORT = qw(expand unexpand $tabstop);
17
18$tabstop = 8;
19
20sub expand
21{
22 my @l = @_;
23 for $_ (@l) {
24 1 while s/^([^\t]*)(\t+)/
25 $1 . (" " x
26 ($tabstop * length($2)
27 - (length($1) % $tabstop)))
28 /e;
29 }
30 return @l;
31}
32
33sub unexpand
34{
35 my @l = &expand(@_);
36 my @e;
37 for $x (@l) {
38 @e = split(/(.{$tabstop})/,$x);
39 for $_ (@e) {
40 s/ +$/\t/;
41 }
42 $x = join('',@e);
43 }
44 return @l;
45}
46
471;