Commit bea5b318 authored by sikeda's avatar sikeda
Browse files

[dev] Introducing Sympa::Tools::Text::pad().


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@12842 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent 54317314
......@@ -376,6 +376,7 @@ our %cpan_modules = (
mandatory => 1,
'gettext_id' => 'used to get time with sub-second precision',
},
# Unicode::GCString is included in Unicode-LineBreak.
'URI::Escape' => {
required_version => '3.28', # Included in URI-1.35.
package_name => 'URI',
......
......@@ -32,6 +32,7 @@ use Encode::MIME::Header; # 'MIME-Q' encoding.
use HTML::Entities qw();
use MIME::EncWords;
use Text::LineFold;
use Unicode::GCString;
use URI::Escape qw();
use if (5.008 < $] && $] < 5.016), qw(Unicode::CaseFold fc);
use if (5.016 <= $]), qw(feature fc);
......@@ -290,6 +291,24 @@ sub _url_query_string {
}
}
sub pad {
my $str = shift;
my $width = shift;
return $str unless $width and defined $str;
my $ustr = Encode::is_utf8($str) ? $str : Encode::decode_utf8($str);
my $cols = Unicode::GCString->new($ustr)->columns;
unless ($cols < abs $width) {
return $str;
} elsif ($width < 0) {
return $str . (' ' x (-$width - $cols));
} else {
return (' ' x ($width - $cols)) . $str;
}
}
# Old name: tools::qdecode_filename().
sub qdecode_filename {
my $filename = shift;
......@@ -607,6 +626,31 @@ Returns:
Constructed URL.
=item pad ( $str, $width )
Pads space a string so that result will not be narrower than given width.
Parameters:
=over
=item $str
A string.
=item $width
If $width is false value or width of $str is not less than $width,
does nothing.
If $width is less than C<0>, pads right.
Otherwise, pads left.
=back
Returns:
Padded string.
=item qdecode_filename ( $filename )
Q-Decodes web file name.
......@@ -713,4 +757,6 @@ on Sympa 6.2.10.
decode_html(), encode_html(), encode_uri() and mailtourl()
were added on Sympa 6.2.14, and escape_url() was deprecated.
pad() was added on Sympa 6.2.17.
=cut
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment