Data-ParseBinary
view release on metacpan or search on metacpan
lib/Data/ParseBinary.pm view on Meta::CPAN
UTF-32LE
UTF-32BE
UTF-16LE
UTF-16BE
UTF-8
utf8
or any single-byte encoding supported by the Encode module
for example: iso-8859-8
If you don't know if your unicode string is BE or LE, then it's probably BE.
=head3 String (constant length / meta)
A string with constant length:
String("foo", 5)->parse("hello")
# returns "hello"
A string with variable length, and encoding:
t/04encodings.t view on Meta::CPAN
ok( $s->build($ch) eq $oc, "Char UTF-32LE: Build: high char");
ok( $s->parse($oc) eq $ch, "Char UTF-32LE: Parse: high char");
foreach my $enc (qw{UTF-32 utf UTF-16 UTF UTF8 ucs-2}) {
eval { Char("c", $enc) };
ok( $@, "Char died on encoding: $enc");
}
$s = Char("c", "iso-8859-8");
$ch = "\x{05D0}"; # the letter "Alef" in hebrew, in unicode
$oc = "\xE0"; # the same in iso-8859-8
ok( $s->build($ch) eq $oc, "Char hebrew: Build: simple");
ok( $s->parse($oc) eq $ch, "Char hebrew: Parse: simple");
my $love_decoded = "\x{05D0}\x{05D4}\x{05D1}\x{05D4}";
my $love_encoded = "\xd7\x90\xd7\x94\xd7\x91\xd7\x94";
$s = PaddedString("foo", 10, encoding => "utf8", padchar => "\0");
$oc = $love_encoded."\0\0";
( run in 0.495 second using v1.01-cache-2.11-cpan-f29a10751f0 )