+# Bug 264146.
+# Copied from Text::Wrap.
+# The only modified thing is:
+# We trim _just_ tab/space etc. but not \n/\r.
+# So \h should cover \x09, \x0B, \x0C and \x20.
+# \s treats even \n/\r as whitespace.
+sub text_fill {
+ my ($ip, $xp, @raw) = @_;
+ my @para;
+ my $pp;
+
+ for $pp ( split(/\n\s+/, join("\n", @raw)) ) {
+ $pp =~ s/\h+/ /g;
+ my $x = Text::Wrap::wrap($ip, $xp, $pp);
+ push(@para, $x);
+ }
+
+ # if paragraph_indent is the same as line_indent,
+ # separate paragraphs with blank lines
+ my $ps = ($ip eq $xp) ? "\n\n" : "\n";
+ return join ($ps, @para);
+}
+