You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
935 B

package Subtitle::Utils;
use strict;
use warnings;
use base 'Exporter';
our @EXPORT_OK = qw(
chomp_all strip_bom trim
);
our %EXPORT_TAGS = (
string => [qw(chomp_all strip_bom trim)],
);
## string sunctions
sub chomp_all {
return unless @_;
return $_ =~ s/[\r\n]+$//o for @_;
}
sub strip_bom {
return unless @_;
return $_[0] =~ s/^\xEF\xBB\xBF//o;
}
sub trim {
return unless @_;
$_ =~ s/(^\s+|\s+$)//go for @_;
}
1;
=pod
=head1 NAME
Subtitle::Utils -- usefull generic routines
=head1 SYNOPSYS
use Subtitle::Utils qw(:all);
=head1 FUNCTIONS / STRINGS
use Subtitle::Utils qw(:string);
=head2 C<chomp_all>
chomp($line);
chomp($line1, $line2);
In-place strips newlines (CR/LF) from line.
=head2 C<strip_bom>
strip_bom($line);
In-place strips Unicode's BOM (Byte Order Mark) from line.
=head2 C<trim>
trim($line);
In-place strips leading and trailing spaces from the given string
=cut