perl-unicode

tiny examples for Japanese Kana composition using Perl 5.8.0

2002-07-16 06:30:05
This is encoded in UTF-8 and Quoted Printable.
If decoded, these codes will explain themselves.

Note: U+3099 and U+309A are the combining "dakuten" and "han-dakuten".

#!perl
use 5.008;
use utf8;
use Unicode::Normalize qw(:normalize);

sub composeKana {
    (my $str =3D shift) =3D~
        s/([\p{InHiragana}\p{InKatakana}]+)/compose($1)/eg;
    return $str;
}

sub normalHalfFull {
    (my $str =3D shift) =3D~
        s/(\p{InHalfwidthAndFullwidthForms}+)/NFKC($1)/eg;
    return $str;
}

print composeKana("=E3=81=8B\x{3099}=E3=83=9B\x{309A}=E3=82=9D\x{3099}")
   eq "=E3=81=8C=E3=83=9D=E3=82=9E"
    ? "ok" : "not ok", "\n";

print normalHalfFull("=EF=BE=8A=EF=BE=9F=EF=BD=B0=EF=BE=99=E3=80=80=EF=BC=
=B0=EF=BD=85=EF=BD=92=EF=BD=8C")
   eq "=E3=83=91=E3=83=BC=E3=83=AB=E3=80=80Perl"
    ? "ok" : "not ok", "\n";

__END__

SADAHIRO Tomoyuki

<Prev in Thread] Current Thread [Next in Thread>
  • tiny examples for Japanese Kana composition using Perl 5.8.0, SADAHIRO Tomoyuki <=