lib/Text/Soundex.t See if Soundex works
lib/Text/Tabs.pm Do expand and unexpand
lib/Text/TabsWrap/CHANGELOG ChangeLog for Tabs+Wrap
+lib/Text/TabsWrap/t/37000.t See if Text::Tabs is working
+lib/Text/TabsWrap/t/39548.t See if Text::Tabs is working
+lib/Text/TabsWrap/t/Jochen.t See if Text::Tabs is working
+lib/Text/TabsWrap/t/belg4mit.t See if Text::Tabs is working
lib/Text/TabsWrap/t/fill.t See if Text::Wrap::fill works
+lib/Text/TabsWrap/t/sep.t See if Text::Tabs is working
+lib/Text/TabsWrap/t/sep2.t See if Text::Tabs is working
lib/Text/TabsWrap/t/tabs.t See if Text::Tabs works
lib/Text/TabsWrap/t/wrap.t See if Text::Wrap::wrap works
lib/Text/Wrap.pm Paragraph formatter
@EXPORT = qw(expand unexpand $tabstop);
use vars qw($VERSION $tabstop $debug);
-$VERSION = 2005.0824;
+$VERSION = 2007.0711_01;
use strict;
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 = $_;
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
=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.
+= 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
--- /dev/null
+#!/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";
+
--- /dev/null
+#!/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";
--- /dev/null
+#!/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";
+
--- /dev/null
+#!/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";
+
-#!./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
$| = 1;
-print "1..", @tests/2, "\n";
+print "1..";
+print @tests/2;
+print "\n";
use Text::Wrap;
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;
--- /dev/null
+#!/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++;
+
--- /dev/null
+#!/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++;
+
@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);
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;
? 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";
}
$huge = 'overflow';
B<Example 3>
-
+
use Text::Wrap
$Text::Wrap::columns = 72;
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.
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.