summaryrefslogtreecommitdiff
path: root/lib/Text/Tabs.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Text/Tabs.pm')
-rw-r--r--lib/Text/Tabs.pm50
1 files changed, 33 insertions, 17 deletions
diff --git a/lib/Text/Tabs.pm b/lib/Text/Tabs.pm
index c90d1aa672..fa866988cf 100644
--- a/lib/Text/Tabs.pm
+++ b/lib/Text/Tabs.pm
@@ -2,10 +2,10 @@
# expand and unexpand tabs as per the unix expand and
# unexpand programs.
#
-# expand and unexpand operate on arrays of lines. Do not
-# feed strings that contain newlines to them.
+# expand and unexpand operate on arrays of lines.
#
# David Muir Sharnoff <muir@idiom.com>
+# Version: 4/19/95
#
package Text::Tabs;
@@ -19,29 +19,45 @@ $tabstop = 8;
sub expand
{
- my @l = @_;
- for $_ (@l) {
- 1 while s/^([^\t]*)(\t+)/
- $1 . (" " x
- ($tabstop * length($2)
- - (length($1) % $tabstop)))
- /e;
+ my (@l) = @_;
+ my $l, @k;
+ my $nl;
+ for $l (@l) {
+ $nl = $/ if chomp($l);
+ @k = split($/,$l);
+ for $_ (@k) {
+ 1 while s/^([^\t]*)(\t+)/
+ $1 . (" " x
+ ($tabstop * length($2)
+ - (length($1) % $tabstop)))
+ /e;
+ }
+ $l = join("\n",@k).$nl;
}
- return @l;
+ return @l if $#l > 0;
+ return $l[0];
}
sub unexpand
{
- my @l = &expand(@_);
+ my (@l) = &expand(@_);
my @e;
- for $x (@l) {
- @e = split(/(.{$tabstop})/,$x);
- for $_ (@e) {
- s/ +$/\t/;
+ my $k, @k;
+ my $nl;
+ for $k (@l) {
+ $nl = $/ if chomp($k);
+ @k = split($/,$k);
+ for $x (@k) {
+ @e = split(/(.{$tabstop})/,$x);
+ for $_ (@e) {
+ s/ +$/\t/;
+ }
+ $x = join('',@e);
}
- $x = join('',@e);
+ $k = join("\n",@k).$nl;
}
- return @l;
+ return @l if $#l > 0;
+ return $l[0];
}
1;