This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate changes from Text::Tabs and Text::Wrap on CPAN
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Wed, 21 Sep 2005 09:37:27 +0000 (09:37 +0000)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Wed, 21 Sep 2005 09:37:27 +0000 (09:37 +0000)
(Text-Tabs+Wrap-2005.0824). Keep local changes.

p4raw-id: //depot/perl@25526

lib/Text/Tabs.pm
lib/Text/TabsWrap/CHANGELOG
lib/Text/Wrap.pm

index b26f8f4..36107fc 100644 (file)
@@ -7,7 +7,7 @@ require Exporter;
 @EXPORT = qw(expand unexpand $tabstop);
 
 use vars qw($VERSION $tabstop $debug);
-$VERSION = 98.112801;
+$VERSION = 2005.0824;
 
 use strict;
 
@@ -16,15 +16,21 @@ BEGIN       {
        $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];
@@ -66,6 +72,20 @@ 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];
+}
+
 
 =head1 NAME
 
@@ -92,6 +112,10 @@ compression with plain ascii!
 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>
index 7f0720a..0ca0a19 100644 (file)
@@ -1,6 +1,19 @@
+= 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.
@@ -8,18 +21,18 @@ 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).
 
@@ -27,9 +40,9 @@ Performance rewrite: use m/\G/ rather than s///.
 
 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
 
@@ -48,15 +61,15 @@ Anyway, I have a bunch of people to thank.  I didn't
 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.
index f12d458..de21d2a 100644 (file)
@@ -6,10 +6,10 @@ require Exporter;
 @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  {
@@ -20,6 +20,7 @@ BEGIN {
        $unexpand = 1;
        $tabstop = 8;
        $separator = "\n";
+       $separator2 = undef;
 }
 
 use Text::Tabs qw(expand unexpand);
@@ -52,7 +53,7 @@ sub wrap
                        $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)
@@ -66,7 +67,11 @@ sub wrap
                        
                $lead = $xp;
                $ll = $nll;
-               $nl = $separator;
+               $nl = defined($separator2)
+                       ? ($remainder eq "\n"
+                               ? "\n"
+                               : $separator2)
+                       : $separator;
        }
        $r .= $remainder;
 
@@ -188,7 +193,10 @@ want to use 8-character tabstops, set C<$Text::Wrap::tabstop> to
 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>.
@@ -205,8 +213,11 @@ C<$huge>.  Now, 'wrap' is the default value.
        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.