DBD-PO
view release on metacpan or search on metacpan
t/02_Text-PO/01_quote.t view on Meta::CPAN
#!perl -T
use strict;
use warnings;
use Carp qw(croak);
use English qw(-no_match_vars $OS_ERROR $INPUT_RECORD_SEPARATOR);
use Test::DBD::PO::Defaults qw($FILE_TEXT_PO $DROP_TABLE);
use Test::More tests => 7 + 1;
use Test::NoWarnings;
use Test::Differences;
BEGIN {
require_ok('IO::File');
require_ok('DBD::PO::Text::PO');
}
my $test_string = join "\n", (
(
map {
join q{}, map { chr $_ } 8 * $_ .. 8 * $_ + 7;
} 0 .. 15
),
(
map {
join q{}, map { "\\" . chr $_ } 8 * $_ .. 8 * $_ + 7;
} 0 .. 15
),
);
sub quote {
my $string = shift;
my $eol = shift;
my %named = (
#qq{\a} => qq{\\a}, # BEL
#qq{\b} => qq{\\b}, # BS
#qq{\t} => qq{\\t}, # TAB
qq{\n} => qq{\\n}, # LF
#qq{\f} => qq{\\f}, # FF
#qq{\r} => qq{\\r}, # CR
qq{"} => qq{\\"},
qq{\\} => qq{\\\\},
);
$string =~ s{
( [^ !#$%&'()*+,\-.\/0-9:;<=>?@A-Z\[\]\^_`a-z{|}~] )
}{
ord $1 < 0x80
? (
exists $named{$1}
? $named{$1}
: sprintf '\x%02x', ord $1
)
: $1;
}xmsge;
$string = qq{"$string"};
# multiline
if ($string =~ s{\A ( " .*? \\n )}{""\n$1}xms) {
$string =~ s{\\n}{\\n"$eol"}xmsg;
}
return $string;
}
my $po_string = quote($test_string, "\n");
# write po file
{
my $file_handle = IO::File->new();
isa_ok($file_handle, 'IO::File');
( run in 0.714 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )