diff options
author | Steve Peters <steve@fisharerojo.org> | 2006-07-11 12:31:10 +0000 |
---|---|---|
committer | Steve Peters <steve@fisharerojo.org> | 2006-07-11 12:31:10 +0000 |
commit | 95925ace7dd478659af55ea84cc2d7e598cbf885 (patch) | |
tree | 45c78d2785b032f1f6da951e4aaff92f66b88123 /lib | |
parent | 9e4425f7401960922972922c0fbf30ed45522d5e (diff) | |
download | perl-95925ace7dd478659af55ea84cc2d7e598cbf885.tar.gz |
Upgrade to Text-Tabs+Wrap-2006.0711. Keep the local changes from
change #27541. Also, leave out the test files Jacobson.t and
Jacobson2.t which both generated several warnings.
p4raw-link: @27541 on //depot/perl: abc0156ba8cc024916c0d1e664c4488f0cbc55c8
p4raw-id: //depot/perl@28546
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Text/Tabs.pm | 36 | ||||
-rw-r--r-- | lib/Text/TabsWrap/CHANGELOG | 22 | ||||
-rwxr-xr-x | lib/Text/TabsWrap/t/37000.t | 29 | ||||
-rwxr-xr-x | lib/Text/TabsWrap/t/39548.t | 11 | ||||
-rwxr-xr-x | lib/Text/TabsWrap/t/Jochen.t | 11 | ||||
-rwxr-xr-x | lib/Text/TabsWrap/t/belg4mit.t | 18 | ||||
-rwxr-xr-x | lib/Text/TabsWrap/t/fill.t | 17 | ||||
-rwxr-xr-x | lib/Text/TabsWrap/t/sep.t | 173 | ||||
-rwxr-xr-x | lib/Text/TabsWrap/t/sep2.t | 188 | ||||
-rw-r--r-- | lib/Text/Wrap.pm | 44 |
10 files changed, 521 insertions, 28 deletions
diff --git a/lib/Text/Tabs.pm b/lib/Text/Tabs.pm index aa79ecc8ff..ab54c7724f 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 = 2005.0824; +$VERSION = 2007.0711_01; use strict; @@ -44,15 +44,17 @@ sub unexpand my $line; my @lines; my $lastbit; + my $ts_as_space = " "x$tabstop; for $x (@l) { @lines = split("\n", $x, -1); for $line (@lines) { $line = expand($line); @e = split(/(.{$tabstop})/,$line,-1); $lastbit = pop(@e); - $lastbit = '' unless defined $lastbit; + $lastbit = '' + unless defined $lastbit; $lastbit = "\t" - if $lastbit eq " "x$tabstop; + if $lastbit eq $ts_as_space; for $_ (@e) { if ($debug) { my $x = $_; @@ -95,17 +97,35 @@ Text::Tabs -- expand and unexpand tabs per the unix expand(1) and unexpand(1) use Text::Tabs; - $tabstop = 4; + $tabstop = 4; # default = 8 @lines_without_tabs = expand(@lines_with_tabs); @lines_with_tabs = unexpand(@lines_without_tabs); =head1 DESCRIPTION -Text::Tabs does about what the unix utilities expand(1) and unexpand(1) +Text::Tabs does about what the unix utilities expand(1) and unexpand(1) do. Given a line with tabs in it, expand will replace the tabs with the appropriate number of spaces. Given a line with or without tabs in -it, unexpand will add tabs when it can save bytes by doing so. Invisible -compression with plain ascii! +it, unexpand will add tabs when it can save bytes by doing so (just +like C<unexpand -a>). Invisible compression with plain ASCII! + +=head1 EXAMPLE + + #!perl + # unexpand -a + use Text::Tabs; + + while (<>) { + print unexpand $_; + } + +Instead of the C<expand> comand, use: + + perl -MText::Tabs -n -e 'print expand $_' + +Instead of the C<unexpand -a> command, use: + + perl -MText::Tabs -n -e 'print unexpand $_' =head1 BUGS @@ -114,7 +134,7 @@ entire document in one string. Instead feed it an array of lines. =head1 LICENSE -Copyright (C) 1996-2002,2005 David Muir Sharnoff. +Copyright (C) 1996-2002,2005,2006 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. diff --git a/lib/Text/TabsWrap/CHANGELOG b/lib/Text/TabsWrap/CHANGELOG index 0ca0a195d3..f82e58479f 100644 --- a/lib/Text/TabsWrap/CHANGELOG +++ b/lib/Text/TabsWrap/CHANGELOG @@ -1,3 +1,25 @@ += 2006/07/11 + +Further bomb-proofing to pass more tests: Dan Jacobson <jidanni at +jidanni dot org> found another way to generate a "this shouldn't happen". + += 2006/07/05 + +Made documentation and code changes to address perlbug: +https://rt.perl.org/rt3/Ticket/Display.html?id=30229 + +Added in changes from the distributed-with-perl version. This took +care of perlbug: https://rt.perl.org/rt3/Ticket/Display.html?id=34902 +It also took care of suggestion from Matthijs Bomhoff <matthijs +at bomhoff dot nl>. + +Made documentation changes (added EXAMPLES) as per a suggestion +from Gabor Blasko <gblasko at cs dot columbia dot edu> + +belg4mit at MIT dot EDU reported that $columns==1 die'd. No longer. + +Added tests for each bug report. + = 2005/08/24 Added $separator2 and tests for $separator and $separator2 diff --git a/lib/Text/TabsWrap/t/37000.t b/lib/Text/TabsWrap/t/37000.t new file mode 100755 index 0000000000..1efbc70f54 --- /dev/null +++ b/lib/Text/TabsWrap/t/37000.t @@ -0,0 +1,29 @@ +#!/usr/bin/perl -I. + +#Causes Text::Wrap to die... +use warnings; +use strict; +use Text::Wrap; + +my $toPrint = "(1) Category\t(2 or greater) New Category\n\n"; +my $good = "(1) Category\t(2 or greater) New Category\n"; + +my $toprint; + +print "1..6\n"; + +local($Text::Wrap::break) = '\s'; +eval { $toPrint = wrap("","",$toPrint); }; +print $@ ? "not ok 1\n" : "ok 1\n"; +print $toPrint eq $good ? "ok 2\n" : "not ok 2\n"; + +local($Text::Wrap::break) = '\d'; +eval { $toPrint = wrap("","",$toPrint); }; +print $@ ? "not ok 3\n" : "ok 3\n"; +print $toPrint eq $good ? "ok 4\n" : "not ok 4\n"; + +local($Text::Wrap::break) = 'a'; +eval { $toPrint = wrap("","",$toPrint); }; +print $@ ? "not ok 5\n" : "ok 5\n"; +print $toPrint eq $good ? "ok 6\n" : "not ok 6\n"; + diff --git a/lib/Text/TabsWrap/t/39548.t b/lib/Text/TabsWrap/t/39548.t new file mode 100755 index 0000000000..6cca0865c1 --- /dev/null +++ b/lib/Text/TabsWrap/t/39548.t @@ -0,0 +1,11 @@ +#!/usr/bin/perl -w -I. + +# https://rt.perl.org/rt3/Ticket/Display.html?id=39548 + +print "1..1\n"; +require Text::Wrap; +$VAR1 = " (Karl-Bonhoeffer-Nervenklinik zwischen Hermann-Piper-Str. und U-Bahnhof) "; +$VAR2 = " "; +$VAR3 = "(5079,19635 5124,19634 5228,19320 5246,19244)\n"; +eval { Text::Wrap::wrap($VAR1,$VAR2,$VAR3); }; +print $@ ? "not ok 1\n" : "ok 1\n"; diff --git a/lib/Text/TabsWrap/t/Jochen.t b/lib/Text/TabsWrap/t/Jochen.t new file mode 100755 index 0000000000..d4a3a8b76a --- /dev/null +++ b/lib/Text/TabsWrap/t/Jochen.t @@ -0,0 +1,11 @@ +#!/usr/bin/perl -I. + +use Text::Wrap; + +print "1..1\n"; + +$Text::Wrap::columns = 1; +eval { wrap('', '', ''); }; + +print $@ ? "not ok 1\n" : "ok 1\n"; + diff --git a/lib/Text/TabsWrap/t/belg4mit.t b/lib/Text/TabsWrap/t/belg4mit.t new file mode 100755 index 0000000000..2d10342c5f --- /dev/null +++ b/lib/Text/TabsWrap/t/belg4mit.t @@ -0,0 +1,18 @@ +#!/usr/bin/perl -I. + +use Text::Wrap; + +print "1..1\n"; + +$Text::Wrap::columns = 1; +eval { wrap('', '', 'H4sICNoBwDoAA3NpZwA9jbsNwDAIRHumuC4NklvXTOD0KSJEnwU8fHz4Q8M9i3sGzkS7BBrm +OkCTwsycb4S3DloZuMIYeXpLFqw5LaMhXC2ymhreVXNWMw9YGuAYdfmAbwomoPSyFJuFn2x8 +Opr8bBBidccAAAA'); }; + +if ($@) { + my $e = $@; + $e =~ s/^/# /gm; + print $e; +} +print $@ ? "not ok 1\n" : "ok 1\n"; + diff --git a/lib/Text/TabsWrap/t/fill.t b/lib/Text/TabsWrap/t/fill.t index 3d5b98fd9f..dab043297e 100755 --- a/lib/Text/TabsWrap/t/fill.t +++ b/lib/Text/TabsWrap/t/fill.t @@ -1,11 +1,4 @@ -#!./perl -w - -BEGIN { - chdir 't' if -d 't'; - @INC = '../lib'; -} - -use Text::Wrap qw(&fill); +#!/usr/bin/perl -w -I. @tests = (split(/\nEND\n/s, <<DONE)); TEST1 @@ -56,7 +49,9 @@ DONE $| = 1; -print "1..", @tests/2, "\n"; +print "1.."; +print @tests/2; +print "\n"; use Text::Wrap; @@ -75,8 +70,8 @@ while (@tests) { print "ok $tn\n"; } elsif ($rerun) { my $oi = $in; - write_file("#o", $back); - write_file("#e", $out); + write_file("#o", $back); + write_file("#e", $out); foreach ($in, $back, $out) { s/\t/^I\t/gs; s/\n/\$\n/gs; diff --git a/lib/Text/TabsWrap/t/sep.t b/lib/Text/TabsWrap/t/sep.t new file mode 100755 index 0000000000..094f720bc1 --- /dev/null +++ b/lib/Text/TabsWrap/t/sep.t @@ -0,0 +1,173 @@ +#!/usr/bin/perl -I. + +@tests = (split(/\nEND\n/s, <<DONE)); +TEST1 +This +is +a +test +END + This = is= a= test +END +TEST2 +This is a test of a very long line. It should be broken up and put onto multiple lines. +This is a test of a very long line. It should be broken up and put onto multiple lines. + +This is a test of a very long line. It should be broken up and put onto multiple lines. +END + This is a test of a very long line. It should be broken up and put onto= multiple lines.= This is a test of a very long line. It should be broken up and put onto= multiple lines.= = This is a test of a very long line. It should be broken up and put onto= multiple lines. +END +TEST3 +This is a test of a very long line. It should be broken up and put onto multiple lines. +END + This is a test of a very long line. It should be broken up and put onto= multiple lines. +END +TEST4 +This is a test of a very long line. It should be broken up and put onto multiple lines. + +END + This is a test of a very long line. It should be broken up and put onto= multiple lines. + +END +TEST5 +This is a test of a very long line. It should be broken up and put onto multiple This is a test of a very long line. It should be broken up and put +END + This is a test of a very long line. It should be broken up and put onto= multiple This is a test of a very long line. It should be broken up and= put +END +TEST6 +11111111 22222222 33333333 44444444 55555555 66666666 77777777 888888888 999999999 aaaaaaaaa bbbbbbbbb ccccccccc ddddddddd eeeeeeeee ffffffff gggggggg hhhhhhhh iiiiiiii jjjjjjjj kkkkkkkk llllllll mmmmmmmmm nnnnnnnnn ooooooooo ppppppppp qqqqqqqqq rrrrrrrrr sssssssss +END + 11111111 22222222 33333333 44444444 55555555 66666666 77777777 888888888= 999999999 aaaaaaaaa bbbbbbbbb ccccccccc ddddddddd eeeeeeeee ffffffff= gggggggg hhhhhhhh iiiiiiii jjjjjjjj kkkkkkkk llllllll mmmmmmmmm nnnnnnnnn= ooooooooo ppppppppp qqqqqqqqq rrrrrrrrr sssssssss +END +TEST7 +c3t1d0s6 c4t1d0s6 c5t1d0s6 c6t1d0s6 c7t1d0s6 c8t1d0s6 c9t1d0s6 c10t1d0s6 c11t1d0s6 c12t1d0s6 c13t1d0s6 c14t1d0s6 c15t1d0s6 c16t1d0s6 c3t1d0s0 c4t1d0s0 c5t1d0s0 c6t1d0s0 c7t1d0s0 c8t1d0s0 c9t1d0s0 c10t1d0s0 c11t1d0s0 c12t1d0s0 c13t1d0s0 c14t1d0s0 c15t1d0s0 c16t1d0s0 +END + c3t1d0s6 c4t1d0s6 c5t1d0s6 c6t1d0s6 c7t1d0s6 c8t1d0s6 c9t1d0s6 c10t1d0s6= c11t1d0s6 c12t1d0s6 c13t1d0s6 c14t1d0s6 c15t1d0s6 c16t1d0s6 c3t1d0s0= c4t1d0s0 c5t1d0s0 c6t1d0s0 c7t1d0s0 c8t1d0s0 c9t1d0s0 c10t1d0s0 c11t1d0s0= c12t1d0s0 c13t1d0s0 c14t1d0s0 c15t1d0s0 c16t1d0s0 +END +TEST8 +A test of a very very long word. +a123456789b123456789c123456789d123456789e123456789f123456789g123456789g1234567 +END + A test of a very very long word.= a123456789b123456789c123456789d123456789e123456789f123456789g123456789g123= 4567 +END +TEST9 +A test of a very very long word. a123456789b123456789c123456789d123456789e123456789f123456789g123456789g1234567 +END + A test of a very very long word. = a123456789b123456789c123456789d123456789e123456789f123456789g123456789g123= 4567 +END +TEST10 +my mother once said +"never eat paste my darling" +would that I heeded +END + my mother once said= "never eat paste my darling"= would that I heeded +END +TEST11 +This_is_a_word_that_is_too_long_to_wrap_we_want_to_make_sure_that_the_program_does_not_crash_and_burn +END + This_is_a_word_that_is_too_long_to_wrap_we_want_to_make_sure_that_the_pr= ogram_does_not_crash_and_burn +END +TEST12 +This + +Has + +Blank + +Lines + +END + This= = Has= = Blank= = Lines + +END +DONE + + +$| = 1; + +print "1..", 1 +@tests, "\n"; + +use Text::Wrap; +$Text::Wrap::separator = '='; + +$rerun = $ENV{'PERL_DL_NONLAZY'} ? 0 : 1; + +$tn = 1; + +@st = @tests; +while (@st) { + my $in = shift(@st); + my $out = shift(@st); + + $in =~ s/^TEST(\d+)?\n//; + + my $back = wrap(' ', ' ', $in); + + if ($back eq $out) { + print "ok $tn\n"; + } elsif ($rerun) { + my $oi = $in; + foreach ($in, $back, $out) { + s/\t/^I\t/gs; + s/\n/\$\n/gs; + } + print "------------ input ------------\n"; + print $in; + print "\n------------ output -----------\n"; + print $back; + print "\n------------ expected ---------\n"; + print $out; + print "\n-------------------------------\n"; + $Text::Wrap::debug = 1; + wrap(' ', ' ', $oi); + exit(1); + } else { + print "not ok $tn\n"; + } + $tn++; + +} + +@st = @tests; +while(@st) { + my $in = shift(@st); + my $out = shift(@st); + + $in =~ s/^TEST(\d+)?\n//; + + my @in = split("\n", $in, -1); + @in = ((map { "$_\n" } @in[0..$#in-1]), $in[-1]); + + my $back = wrap(' ', ' ', @in); + + if ($back eq $out) { + print "ok $tn\n"; + } elsif ($rerun) { + my $oi = $in; + foreach ($in, $back, $out) { + s/\t/^I\t/gs; + s/\n/\$\n/gs; + } + print "------------ input2 ------------\n"; + print $in; + print "\n------------ output2 -----------\n"; + print $back; + print "\n------------ expected2 ---------\n"; + print $out; + print "\n-------------------------------\n"; + $Text::Wrap::debug = 1; + wrap(' ', ' ', $oi); + exit(1); + } else { + print "not ok $tn\n"; + } + $tn++; +} + +$Text::Wrap::huge = 'overflow'; + +my $tw = 'This_is_a_word_that_is_too_long_to_wrap_we_want_to_make_sure_that_the_program_does_not_crash_and_burn'; +my $w = wrap('zzz','yyy',$tw); +print (($w eq "zzz$tw") ? "ok $tn\n" : "not ok $tn"); +$tn++; + diff --git a/lib/Text/TabsWrap/t/sep2.t b/lib/Text/TabsWrap/t/sep2.t new file mode 100755 index 0000000000..4eb8ab563c --- /dev/null +++ b/lib/Text/TabsWrap/t/sep2.t @@ -0,0 +1,188 @@ +#!/usr/bin/perl -I. + +@tests = (split(/\nEND\n/s, <<DONE)); +TEST1 +This +is +a +test +END + This + is + a + test +END +TEST2 +This is a test of a very long line. It should be broken up and put onto multiple lines. +This is a test of a very long line. It should be broken up and put onto multiple lines. + +This is a test of a very long line. It should be broken up and put onto multiple lines. +END + This is a test of a very long line. It should be broken up and put onto= multiple lines. + This is a test of a very long line. It should be broken up and put onto= multiple lines. + + This is a test of a very long line. It should be broken up and put onto= multiple lines. +END +TEST3 +This is a test of a very long line. It should be broken up and put onto multiple lines. +END + This is a test of a very long line. It should be broken up and put onto= multiple lines. +END +TEST4 +This is a test of a very long line. It should be broken up and put onto multiple lines. + +END + This is a test of a very long line. It should be broken up and put onto= multiple lines. + +END +TEST5 +This is a test of a very long line. It should be broken up and put onto multiple This is a test of a very long line. It should be broken up and put +END + This is a test of a very long line. It should be broken up and put onto= multiple This is a test of a very long line. It should be broken up and= put +END +TEST6 +11111111 22222222 33333333 44444444 55555555 66666666 77777777 888888888 999999999 aaaaaaaaa bbbbbbbbb ccccccccc ddddddddd eeeeeeeee ffffffff gggggggg hhhhhhhh iiiiiiii jjjjjjjj kkkkkkkk llllllll mmmmmmmmm nnnnnnnnn ooooooooo ppppppppp qqqqqqqqq rrrrrrrrr sssssssss +END + 11111111 22222222 33333333 44444444 55555555 66666666 77777777 888888888= 999999999 aaaaaaaaa bbbbbbbbb ccccccccc ddddddddd eeeeeeeee ffffffff= gggggggg hhhhhhhh iiiiiiii jjjjjjjj kkkkkkkk llllllll mmmmmmmmm nnnnnnnnn= ooooooooo ppppppppp qqqqqqqqq rrrrrrrrr sssssssss +END +TEST7 +c3t1d0s6 c4t1d0s6 c5t1d0s6 c6t1d0s6 c7t1d0s6 c8t1d0s6 c9t1d0s6 c10t1d0s6 c11t1d0s6 c12t1d0s6 c13t1d0s6 c14t1d0s6 c15t1d0s6 c16t1d0s6 c3t1d0s0 c4t1d0s0 c5t1d0s0 c6t1d0s0 c7t1d0s0 c8t1d0s0 c9t1d0s0 c10t1d0s0 c11t1d0s0 c12t1d0s0 c13t1d0s0 c14t1d0s0 c15t1d0s0 c16t1d0s0 +END + c3t1d0s6 c4t1d0s6 c5t1d0s6 c6t1d0s6 c7t1d0s6 c8t1d0s6 c9t1d0s6 c10t1d0s6= c11t1d0s6 c12t1d0s6 c13t1d0s6 c14t1d0s6 c15t1d0s6 c16t1d0s6 c3t1d0s0= c4t1d0s0 c5t1d0s0 c6t1d0s0 c7t1d0s0 c8t1d0s0 c9t1d0s0 c10t1d0s0 c11t1d0s0= c12t1d0s0 c13t1d0s0 c14t1d0s0 c15t1d0s0 c16t1d0s0 +END +TEST8 +A test of a very very long word. +a123456789b123456789c123456789d123456789e123456789f123456789g123456789g1234567 +END + A test of a very very long word. + a123456789b123456789c123456789d123456789e123456789f123456789g123456789g123= 4567 +END +TEST9 +A test of a very very long word. a123456789b123456789c123456789d123456789e123456789f123456789g123456789g1234567 +END + A test of a very very long word. = a123456789b123456789c123456789d123456789e123456789f123456789g123456789g123= 4567 +END +TEST10 +my mother once said +"never eat paste my darling" +would that I heeded +END + my mother once said + "never eat paste my darling" + would that I heeded +END +TEST11 +This_is_a_word_that_is_too_long_to_wrap_we_want_to_make_sure_that_the_program_does_not_crash_and_burn +END + This_is_a_word_that_is_too_long_to_wrap_we_want_to_make_sure_that_the_pr= ogram_does_not_crash_and_burn +END +TEST12 +This + +Has + +Blank + +Lines + +END + This + + Has + + Blank + + Lines + +END +DONE + + +$| = 1; + +print "1..", 1 +@tests, "\n"; + +use Text::Wrap; +$Text::Wrap::separator2 = '='; + +$rerun = $ENV{'PERL_DL_NONLAZY'} ? 0 : 1; + +$tn = 1; + +@st = @tests; +while (@st) { + my $in = shift(@st); + my $out = shift(@st); + + $in =~ s/^TEST(\d+)?\n//; + + my $back = wrap(' ', ' ', $in); + + if ($back eq $out) { + print "ok $tn\n"; + } elsif ($rerun) { + my $oi = $in; + foreach ($in, $back, $out) { + s/\t/^I\t/gs; + s/\n/\$\n/gs; + } + print "------------ input ------------\n"; + print $in; + print "\n------------ output -----------\n"; + print $back; + print "\n------------ expected ---------\n"; + print $out; + print "\n-------------------------------\n"; + $Text::Wrap::debug = 1; + wrap(' ', ' ', $oi); + exit(1); + } else { + print "not ok $tn\n"; + } + $tn++; + +} + +@st = @tests; +while(@st) { + my $in = shift(@st); + my $out = shift(@st); + + $in =~ s/^TEST(\d+)?\n//; + + my @in = split("\n", $in, -1); + @in = ((map { "$_\n" } @in[0..$#in-1]), $in[-1]); + + my $back = wrap(' ', ' ', @in); + + if ($back eq $out) { + print "ok $tn\n"; + } elsif ($rerun) { + my $oi = $in; + foreach ($in, $back, $out) { + s/\t/^I\t/gs; + s/\n/\$\n/gs; + } + print "------------ input2 ------------\n"; + print $in; + print "\n------------ output2 -----------\n"; + print $back; + print "\n------------ expected2 ---------\n"; + print $out; + print "\n-------------------------------\n"; + $Text::Wrap::debug = 1; + wrap(' ', ' ', $oi); + exit(1); + } else { + print "not ok $tn\n"; + } + $tn++; +} + +$Text::Wrap::huge = 'overflow'; + +my $tw = 'This_is_a_word_that_is_too_long_to_wrap_we_want_to_make_sure_that_the_program_does_not_crash_and_burn'; +my $w = wrap('zzz','yyy',$tw); +print (($w eq "zzz$tw") ? "ok $tn\n" : "not ok $tn"); +$tn++; + diff --git a/lib/Text/Wrap.pm b/lib/Text/Wrap.pm index de21d2a41b..b0e15a7f07 100644 --- a/lib/Text/Wrap.pm +++ b/lib/Text/Wrap.pm @@ -6,7 +6,7 @@ require Exporter; @EXPORT = qw(wrap fill); @EXPORT_OK = qw($columns $break $huge); -$VERSION = 2005.0824_01; +$VERSION = 2006.0711; use vars qw($VERSION $columns $debug $break $huge $unexpand $tabstop $separator $separator2); @@ -43,8 +43,8 @@ sub wrap use re 'taint'; pos($t) = 0; - while ($t !~ /\G\s*\Z/gc) { - if ($t =~ /\G([^\n]{0,$ll})($break|\n*\z)/xmgc) { + while ($t !~ /\G(?:$break)*\Z/gc) { + if ($t =~ /\G([^\n]{0,$ll})($break|\n+|\z)/xmgc) { $r .= $unexpand ? unexpand($nl . $lead . $1) : $nl . $lead . $1; @@ -54,13 +54,17 @@ sub wrap ? unexpand($nl . $lead . $1) : $nl . $lead . $1; $remainder = defined($separator2) ? $separator2 : $separator; - } elsif ($huge eq 'overflow' && $t =~ /\G([^\n]*?)($break|\z)/xmgc) { + } elsif ($huge eq 'overflow' && $t =~ /\G([^\n]*?)($break|\n+|\z)/xmgc) { $r .= $unexpand ? unexpand($nl . $lead . $1) : $nl . $lead . $1; $remainder = $2; } elsif ($huge eq 'die') { die "couldn't wrap '$t'"; + } elsif ($columns < 2) { + warn "Increasing \$Text::Wrap::columns from $columns to 2"; + $columns = 2; + return ($ip, $xp, @t); } else { die "This shouldn't happen"; } @@ -139,7 +143,7 @@ B<Example 2> $huge = 'overflow'; B<Example 3> - + use Text::Wrap $Text::Wrap::columns = 72; @@ -160,6 +164,8 @@ will destroy any whitespace in the original text. It breaks text into paragraphs by looking for whitespace after a newline. In other respects it acts like wrap(). +Both C<wrap()> and C<fill()> return a single string. + =head1 OVERRIDES C<Text::Wrap::wrap()> has a number of variables that control its behavior. @@ -208,15 +214,35 @@ left intact. Historical notes: 'die' used to be the default value of C<$huge>. Now, 'wrap' is the default value. -=head1 EXAMPLE +=head1 EXAMPLES + +Code: + + print wrap("\t","",<<END); + This is a bit of text that forms + a normal book-style indented paragraph + END + +Result: + + " This is a bit of text that forms + a normal book-style indented paragraph + " + +Code: + + $Text::Wrap::columns=20; + $Text::Wrap::separator="|"; + print wrap("","","This is a bit of text that forms a normal book-style paragraph"); + +Result: - print wrap("\t","","This is a bit of text that forms - a normal book-style paragraph"); + "This is a bit of|text that forms a|normal book-style|paragraph" =head1 LICENSE David Muir Sharnoff <muir@idiom.com> with help from Tim Pierce and -many many others. Copyright (C) 1996-2002 David Muir Sharnoff. +many many others. Copyright (C) 1996-2006 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. |