(Text-Tabs+Wrap-2005.0824). Keep local changes.
p4raw-id: //depot/perl@25526
@EXPORT = qw(expand unexpand $tabstop);
use vars qw($VERSION $tabstop $debug);
-$VERSION = 98.112801;
+$VERSION = 2005.0824;
use strict;
$debug = 0;
}
-sub expand
-{
- my (@l) = @_;
- for $_ (@l) {
- 1 while s/(^|\n)([^\t\n]*)(\t+)/
- $1. $2 . (" " x
- ($tabstop * length($3)
- - (length($2) % $tabstop)))
- /sex;
+sub expand {
+ my @l;
+ my $pad;
+ for ( @_ ) {
+ my $s = '';
+ for (split(/^/m, $_, -1)) {
+ my $offs = 0;
+ s{\t}{
+ $pad = $tabstop - (pos() + $offs) % $tabstop;
+ $offs += $pad - 1;
+ " " x $pad;
+ }eg;
+ $s .= $_;
+ }
+ push(@l, $s);
}
return @l if wantarray;
return $l[0];
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];
+}
+
=head1 NAME
expand doesn't handle newlines very quickly -- do not feed it an
entire document in one string. Instead feed it an array of lines.
-=head1 AUTHOR
+=head1 LICENSE
+
+Copyright (C) 1996-2002,2005 David Muir Sharnoff.
+Copyright (C) 2005 Aristotle Pagaltzis
+This module may be modified, used, copied, and redistributed at your own risk.
+Publicly redistributed modified versions must use a different name.
-David Muir Sharnoff <muir@idiom.com>
+= 2005/08/24
+
+Added $separator2 and tests for $separator and $separator2
+
+Aristotle Pagaltzis <pagaltzis at gmx.de> contributed a new version of
+expand() that is faster.
+
+Jarkko Hietaniemi <jhi at cc.hut.fi> sent in perl change #17917 which
+fixed a bug in wrap.
+
+Matthew Durante <matthew_durante at hotmail.com> and
+Don Buchholz <don at truedisk.com> sent in a doc patches.
+
= 2001/09/29
-Philip Newton <Philip.Newton@gmx.net> sent in a clean patch that
+Philip Newton <Philip.Newton at gmx.net> sent in a clean patch that
added support for defining words differently; that prevents
Text::Wrap from untainting strings; and that fixes a documentation
bug.
So that fill.t can be used in the version included in the perl
distribution, fill.t no longer uses File::Slurp.
-Both Sweth Chandramouli <svc@sweth.net> and Drew Degentesh
-<ddegentesh@daed.com> both objected to the automatic unexpand
+Both Sweth Chandramouli <svc at sweth.net> and Drew Degentesh
+<ddegentesh at daed.com> both objected to the automatic unexpand
that Text::Wrap does on its results. Drew sent a patch which
has been integrated.
-Way back in '97, Joel Earl <jrearl@VNET.IBM.COM> asked that
+Way back in '97, Joel Earl <jrearl at VNET.IBM.COM> asked that
it be possible to use a line separator other than \n when
adding new lines. There is now support for that.
= 2001/01/30
-Bugfix by Michael G Schwern <schwern@pobox.com>: don't add extra
+Bugfix by Michael G Schwern <schwern at pobox.com>: don't add extra
whitespace when working one an array of input (as opposed to a
single string).
You can now specify that words that are too long to wrap can simply
overflow the line. Feature requested by James Hoagland
-<hoagland@SiliconDefense.com> and by John Porter <jdporter@min.net>.
+<hoagland at SiliconDefense.com> and by John Porter <jdporter at min.net>.
-Documentation changes from Rich Bowen <Rich@cre8tivegroup.com>.
+Documentation changes from Rich Bowen <Rich at cre8tivegroup.com>.
= 1998/11/29
use what any of them sent in, but I did take ideas from
all of them. Many sent in complete new implamentations.
- Ivan Brawley <ibrawley@awadi.com.au>
+ Ivan Brawley <ibrawley at awadi.com.au>
- Jacqui Caren <Jacqui.Caren@ig.co.uk>
+ Jacqui Caren <Jacqui.Caren at ig.co.uk>
- Jeff Kowalski <jeff.kowalski@autodesk.com>
+ Jeff Kowalski <jeff.kowalski at autodesk.com>
- Allen Smith <easmith@beatrice.rutgers.edu>
+ Allen Smith <easmith at beatrice.rutgers.edu>
- Sullivan N. Beck <sbeck@cise.ufl.edu>
+ Sullivan N. Beck <sbeck at cise.ufl.edu>
The end result is a very slight change in the API. There
is now an additional package variable: $Text::Wrap::huge.
@EXPORT = qw(wrap fill);
@EXPORT_OK = qw($columns $break $huge);
-$VERSION = 2001.09293;
+$VERSION = 2005.0824_01;
use vars qw($VERSION $columns $debug $break $huge $unexpand $tabstop
- $separator);
+ $separator $separator2);
use strict;
BEGIN {
$unexpand = 1;
$tabstop = 8;
$separator = "\n";
+ $separator2 = undef;
}
use Text::Tabs qw(expand unexpand);
$r .= $unexpand
? unexpand($nl . $lead . $1)
: $nl . $lead . $1;
- $remainder = $separator;
+ $remainder = defined($separator2) ? $separator2 : $separator;
} elsif ($huge eq 'overflow' && $t =~ /\G([^\n]*?)($break|\z)/xmgc) {
$r .= $unexpand
? unexpand($nl . $lead . $1)
$lead = $xp;
$ll = $nll;
- $nl = $separator;
+ $nl = defined($separator2)
+ ? ($remainder eq "\n"
+ ? "\n"
+ : $separator2)
+ : $separator;
}
$r .= $remainder;
the number of characters you do want for your tabstops.
If you want to separate your lines with something other than C<\n>
-then set C<$Text::Wrap::separator> to your preference.
+then set C<$Text::Wrap::separator> to your preference. This replaces
+all newlines with C<$Text::Wrap::separator>. If you just to preserve
+existing newlines but add new breaks with something else, set
+C<$Text::Wrap::separator2> instead.
When words that are longer than C<$columns> are encountered, they
are broken up. C<wrap()> adds a C<"\n"> at column C<$columns>.
print wrap("\t","","This is a bit of text that forms
a normal book-style paragraph");
-=head1 AUTHOR
+=head1 LICENSE
David Muir Sharnoff <muir@idiom.com> with help from Tim Pierce and
-many many others.
+many many others. Copyright (C) 1996-2002 David Muir Sharnoff.
+This module may be modified, used, copied, and redistributed at
+your own risk. Publicly redistributed modified versions must use
+a different name.