summaryrefslogtreecommitdiff
path: root/systems/texlive/tlnet/tlpkg/tlperl/lib/Text/Tabs.pm
diff options
context:
space:
mode:
Diffstat (limited to 'systems/texlive/tlnet/tlpkg/tlperl/lib/Text/Tabs.pm')
-rw-r--r--systems/texlive/tlnet/tlpkg/tlperl/lib/Text/Tabs.pm81
1 files changed, 20 insertions, 61 deletions
diff --git a/systems/texlive/tlnet/tlpkg/tlperl/lib/Text/Tabs.pm b/systems/texlive/tlnet/tlpkg/tlperl/lib/Text/Tabs.pm
index 07fe2b8b02..b6c826ded9 100644
--- a/systems/texlive/tlnet/tlpkg/tlperl/lib/Text/Tabs.pm
+++ b/systems/texlive/tlnet/tlpkg/tlperl/lib/Text/Tabs.pm
@@ -1,44 +1,32 @@
-package Text::Tabs;
-
-require Exporter;
-
-@ISA = (Exporter);
-@EXPORT = qw(expand unexpand $tabstop);
+use strict; use warnings;
-use vars qw($VERSION $SUBVERSION $tabstop $debug);
-$VERSION = 2013.0523;
-$SUBVERSION = 'modern';
-
-use strict;
+package Text::Tabs;
-use 5.010_000;
+BEGIN { require Exporter; *import = \&Exporter::import }
-BEGIN {
- $tabstop = 8;
- $debug = 0;
-}
+our @EXPORT = qw( expand unexpand $tabstop );
-my $CHUNK = qr/\X/;
+our $VERSION = '2021.0814';
+our $SUBVERSION = 'modern'; # back-compat vestige
-sub _xlen (_) { scalar(() = $_[0] =~ /$CHUNK/g) }
-sub _xpos (_) { _xlen( substr( $_[0], 0, pos($_[0]) ) ) }
+our $tabstop = 8;
sub expand {
my @l;
my $pad;
for ( @_ ) {
+ defined or do { push @l, ''; next };
my $s = '';
for (split(/^/m, $_, -1)) {
- my $offs = 0;
- s{\t}{
- # this works on both 5.10 and 5.11
- $pad = $tabstop - (_xlen(${^PREMATCH}) + $offs) % $tabstop;
- # this works on 5.11, but fails on 5.10
- #XXX# $pad = $tabstop - (_xpos() + $offs) % $tabstop;
- $offs += $pad - 1;
- " " x $pad;
- }peg;
- $s .= $_;
+ my $offs;
+ for (split(/\t/, $_, -1)) {
+ if (defined $offs) {
+ $pad = $tabstop - $offs % $tabstop;
+ $s .= " " x $pad;
+ }
+ $s .= $_;
+ $offs = () = /\PM/g;
+ }
}
push(@l, $s);
}
@@ -56,21 +44,17 @@ sub unexpand
my $lastbit;
my $ts_as_space = " " x $tabstop;
for $x (@l) {
+ defined $x or next;
@lines = split("\n", $x, -1);
for $line (@lines) {
$line = expand($line);
- @e = split(/(${CHUNK}{$tabstop})/,$line,-1);
+ @e = split(/((?:\PM\pM*){$tabstop})/,$line,-1);
$lastbit = pop(@e);
$lastbit = ''
unless defined $lastbit;
$lastbit = "\t"
if $lastbit eq $ts_as_space;
for $_ (@e) {
- if ($debug) {
- my $x = $_;
- $x =~ s/\t/^I\t/gs;
- print "sub on '$x'\n";
- }
s/ +$/\t/;
}
$line = join('',@e, $lastbit);
@@ -82,22 +66,8 @@ sub unexpand
}
1;
-__END__
-
-sub expand
-{
- my (@l) = @_;
- for $_ (@l) {
- 1 while s/(^|\n)([^\t\n]*)(\t+)/
- $1. $2 . (" " x
- ($tabstop * length($3)
- - (length($2) % $tabstop)))
- /sex;
- }
- return @l if wantarray;
- return $l[0];
-}
+__END__
=head1 NAME
@@ -164,17 +134,6 @@ Instead of the shell's C<unexpand -a> command, use:
perl -MText::Tabs -n -e 'print unexpand $_'
-=head1 SUBVERSION
-
-This module comes in two flavors: one for modern perls (5.10 and above)
-and one for ancient obsolete perls. The version for modern perls has
-support for Unicode. The version for old perls does not. You can tell
-which version you have installed by looking at C<$Text::Tabs::SUBVERSION>:
-it is C<old> for obsolete perls and C<modern> for current perls.
-
-This man page is for the version for modern perls and so that's probably
-what you've got.
-
=head1 BUGS
Text::Tabs handles only tabs (C<"\t">) and combining characters (C</\pM/>). It doesn't