diff options
author | Dave Mitchell <davem@fdisolutions.com> | 2005-04-21 21:22:54 +0000 |
---|---|---|
committer | Dave Mitchell <davem@fdisolutions.com> | 2005-04-21 21:22:54 +0000 |
commit | 818675a5006285acc41be05f4d63d56374ea5eca (patch) | |
tree | b8ae6482bb1436ae31c20ed8c34838ae75da6452 /lib/Text | |
parent | 27da23d53ccce622bc51822f59df8def79b4df95 (diff) | |
download | perl-818675a5006285acc41be05f4d63d56374ea5eca.tar.gz |
[perl #34902] Text::Wrap::wrap() fails with non-space separator
p4raw-id: //depot/perl@24273
Diffstat (limited to 'lib/Text')
-rwxr-xr-x | lib/Text/TabsWrap/t/wrap.t | 22 | ||||
-rw-r--r-- | lib/Text/Wrap.pm | 8 |
2 files changed, 23 insertions, 7 deletions
diff --git a/lib/Text/TabsWrap/t/wrap.t b/lib/Text/TabsWrap/t/wrap.t index 369512d27e..8ff4217826 100755 --- a/lib/Text/TabsWrap/t/wrap.t +++ b/lib/Text/TabsWrap/t/wrap.t @@ -5,7 +5,7 @@ BEGIN { @INC = '../lib'; } -@tests = (split(/\nEND\n/s, <<DONE)); +@tests = (split(/\nEND\n/s, <<'DONE')); TEST1 This is @@ -117,6 +117,17 @@ END Lines END +TEST13 break=\d +I saw 3 ships come sailing in +END + I saw 3 ships come sailing in +END +TEST14 break=\d +the.quick.brown.fox.jumps.over.the.9.lazy.dogs.for.no.good.reason.whatsoever.apparently +END + the.quick.brown.fox.jumps.over.the. + .lazy.dogs.for.no.good.reason.whatsoever.apparently +END DONE @@ -135,7 +146,9 @@ while (@st) { my $in = shift(@st); my $out = shift(@st); - $in =~ s/^TEST(\d+)?\n//; + $in =~ s/^TEST(\d+)( break=(.*))?\n// + or die "bad TEST header line: $in\n"; + local $Text::Wrap::break = $3 if defined $3; my $back = wrap(' ', ' ', $in); @@ -169,7 +182,10 @@ while(@st) { my $in = shift(@st); my $out = shift(@st); - $in =~ s/^TEST(\d+)?\n//; + $in =~ s/^TEST(\d+)( break=(.*))?\n// + or die "bad TEST header line: $in\n"; + local $Text::Wrap::break = $3 if defined $3; + my @in = split("\n", $in, -1); @in = ((map { "$_\n" } @in[0..$#in-1]), $in[-1]); diff --git a/lib/Text/Wrap.pm b/lib/Text/Wrap.pm index 00677f900b..c53eec7d1e 100644 --- a/lib/Text/Wrap.pm +++ b/lib/Text/Wrap.pm @@ -43,7 +43,7 @@ sub wrap pos($t) = 0; while ($t !~ /\G\s*\Z/gc) { - if ($t =~ /\G([^\n]{0,$ll})($break|\z)/xmgc) { + if ($t =~ /\G([^\n]{0,$ll})($break|\n*\z)/xmgc) { $r .= $unexpand ? unexpand($nl . $lead . $1) : $nl . $lead . $1; @@ -151,7 +151,7 @@ be used: it is unlikley you would want to pass in a number. Text::Wrap::fill() is a simple multi-paragraph formatter. It formats each paragraph separately and then joins them together when it's done. It -will destory any whitespace in the original text. It breaks text into +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(). @@ -183,12 +183,12 @@ C<$Text::Wrap::columns> is set in its own namespace without importing it. C<Text::Wrap::wrap()> starts its work by expanding all the tabs in its input into spaces. The last thing it does it to turn spaces back into tabs. If you do not want tabs in your results, set -C<$Text::Wrap::unexapand> to a false value. Likewise if you do not +C<$Text::Wrap::unexpand> to a false value. Likewise if you do not 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::seporator> to your preference. +then set C<$Text::Wrap::separator> to your preference. When words that are longer than C<$columns> are encountered, they are broken up. C<wrap()> adds a C<"\n"> at column C<$columns>. |