From: Nicholas Clark Date: Fri, 9 Oct 2009 08:48:57 +0000 (+0200) Subject: Refactor bytes_to_utf16() into a more generic routine that also handles UTF-8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b6357110eade0edcc5ab86b05942421c02c9b897;p=p5sagit%2Fp5-mst-13.2.git Refactor bytes_to_utf16() into a more generic routine that also handles UTF-8 Remove the direct code for testing UTF-8, calling bytes_to_utf() from a loop for all 3 tested encodings. --- diff --git a/t/comp/require.t b/t/comp/require.t index 06a3421..a0170f0 100644 --- a/t/comp/require.t +++ b/t/comp/require.t @@ -258,18 +258,25 @@ EOT if ($Is_EBCDIC || $Is_UTF8) { exit; } -my $utf8 = pack "C0U", 0xFEFF; +my %templates = ( + utf8 => 'C0U', + utf16be => 'n', + utf16le => 'v', + ); + +sub bytes_to_utf { + my ($enc, $content, $do_bom) = @_; + my $template = $templates{$enc}; + die "Unsupported encoding $enc" unless $template; + return pack "$template*", ($do_bom ? 0xFEFF : ()), unpack "C*", $content; +} -$i++; do_require(qq(${utf8}print "ok $i\n"; 1;\n)); +foreach (sort keys %templates) { + print "# $_\n"; -sub bytes_to_utf16 { - my $utf16 = pack("$_[0]*", unpack("C*", $_[1])); - return @_ == 3 && $_[2] ? pack("$_[0]", 0xFEFF) . $utf16 : $utf16; + $i++; do_require(bytes_to_utf($_, qq(print "ok $i\\n"; 1;\n), 1)); } -$i++; do_require(bytes_to_utf16('n', qq(print "ok $i\\n"; 1;\n), 1)); # BE -$i++; do_require(bytes_to_utf16('v', qq(print "ok $i\\n"; 1;\n), 1)); # LE - END { foreach my $file (@fjles_to_delete) { 1 while unlink $file;