From: Rafael Garcia-Suarez Date: Wed, 21 Sep 2005 09:37:27 +0000 (+0000) Subject: Integrate changes from Text::Tabs and Text::Wrap on CPAN X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8dfcc1616e57fd4d21ae26bcb2e0c92ae93ab613;hp=20fd23efee32fd4dc6fa842669b5cae4a592f9b2;p=p5sagit%2Fp5-mst-13.2.git Integrate changes from Text::Tabs and Text::Wrap on CPAN (Text-Tabs+Wrap-2005.0824). Keep local changes. p4raw-id: //depot/perl@25526 --- diff --git a/lib/Text/Tabs.pm b/lib/Text/Tabs.pm index b26f8f4..36107fc 100644 --- a/lib/Text/Tabs.pm +++ b/lib/Text/Tabs.pm @@ -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 diff --git a/lib/Text/TabsWrap/CHANGELOG b/lib/Text/TabsWrap/CHANGELOG index 7f0720a..0ca0a19 100644 --- a/lib/Text/TabsWrap/CHANGELOG +++ b/lib/Text/TabsWrap/CHANGELOG @@ -1,6 +1,19 @@ += 2005/08/24 + +Added $separator2 and tests for $separator and $separator2 + +Aristotle Pagaltzis contributed a new version of +expand() that is faster. + +Jarkko Hietaniemi sent in perl change #17917 which +fixed a bug in wrap. + +Matthew Durante and +Don Buchholz sent in a doc patches. + = 2001/09/29 -Philip Newton sent in a clean patch that +Philip Newton 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 and Drew Degentesh - both objected to the automatic unexpand +Both Sweth Chandramouli and Drew Degentesh + 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 asked that +Way back in '97, Joel Earl 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 : don't add extra +Bugfix by Michael G Schwern : 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 - and by John Porter . + and by John Porter . -Documentation changes from Rich Bowen . +Documentation changes from Rich Bowen . = 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 + Ivan Brawley - Jacqui Caren + Jacqui Caren - Jeff Kowalski + Jeff Kowalski - Allen Smith + Allen Smith - Sullivan N. Beck + Sullivan N. Beck The end result is a very slight change in the API. There is now an additional package variable: $Text::Wrap::huge. diff --git a/lib/Text/Wrap.pm b/lib/Text/Wrap.pm index f12d458..de21d2a 100644 --- a/lib/Text/Wrap.pm +++ b/lib/Text/Wrap.pm @@ -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 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 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.