| 1 | # Encoding of Korean: McCune-Reischauer Romanization | ||||||||||
| 2 | |||||||||||
| 3 | # $Id: MRR.pm,v 1.5 2007/11/29 14:25:31 you Exp $ | ||||||||||
| 4 | |||||||||||
| 5 | package Encode::Korean::MRR; | ||||||||||
| 6 | |||||||||||
| 7 | 1 | our $VERSION = do { q$Revision: 1.5 $ =~ /\d+\.(\d+)/; sprintf "%.2f", $1 / 100 }; | |||||||||
| 8 | |||||||||||
| 9 | 1 | ▶ | use 5.008008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 1 | ▶ | use Encode::Encoding; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 1 | ▶ | use base qw(Encode::Encoding); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 1 | __PACKAGE__->Define(qw/McCune-Reischauer mrr/); | |||||||||
| 18 | |||||||||||
| 19 | 1 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 1 | require Encode; | |||||||||
| 21 | 1 | Encode->export_to_level(1,@_); | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 1 | ▶ | use Encode::Korean::TransliteratorGenerator; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | |||||||||||
| 26 | # == RULES == | ||||||||||
| 27 | |||||||||||
| 28 | 1 | my $mrr = Encode::Korean::TransliteratorGenerator->new(); | |||||||||
| 29 | |||||||||||
| 30 | 1 | $mrr->consonants(qw(k kk n t tt r m p pp s ss ng ch tch ch' k' t' p' h)); | |||||||||
| 31 | 1 | $mrr->vowels( | |||||||||
| 32 | "a", | ||||||||||
| 33 | "ae", | ||||||||||
| 34 | "ya", | ||||||||||
| 35 | "yae", | ||||||||||
| 36 | "\x{014F}", # \x{014F} latin small letter with breve (ŏ) | ||||||||||
| 37 | "e", | ||||||||||
| 38 | "y\x{014F}", | ||||||||||
| 39 | "ye", | ||||||||||
| 40 | "o", | ||||||||||
| 41 | "wa", | ||||||||||
| 42 | "wae", | ||||||||||
| 43 | "oe", | ||||||||||
| 44 | "yo", | ||||||||||
| 45 | "u", | ||||||||||
| 46 | "w\x{014F}", | ||||||||||
| 47 | "we", | ||||||||||
| 48 | "wi", | ||||||||||
| 49 | "yu", | ||||||||||
| 50 | "\x{016D}", # \x{016D} latin small letter u with breve (ŭ) | ||||||||||
| 51 | "\x{016D}y", | ||||||||||
| 52 | "i" | ||||||||||
| 53 | ); | ||||||||||
| 54 | 1 | $mrr->el('l'); | |||||||||
| 55 | 1 | $mrr->ell('ll'); | |||||||||
| 56 | 1 | $mrr->naught('.'); | |||||||||
| 57 | 1 | $mrr->sep('.'); | |||||||||
| 58 | 1 | $mrr->make(); | |||||||||
| 59 | |||||||||||
| 60 | # == MODES == | ||||||||||
| 61 | 1 | $mrr->enmode('greedy'); | |||||||||
| 62 | 1 | $mrr->demode('greedy'); | |||||||||
| 63 | |||||||||||
| 64 | 0 | ▶ | sub enmode { | ||||||||
|
Subroutine
enmode: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 65 | 0 | my $class = shift; | |||||||||
| 66 | 0 | my($mode) = @_; | |||||||||
| 67 | 0 | $mrr->enmode($mode); | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 0 | ▶ | sub demode { | ||||||||
|
Subroutine
demode: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 71 | 0 | my $class = shift; | |||||||||
| 72 | 0 | my($mode) = @_; | |||||||||
| 73 | 0 | $mrr->demode($mode); | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | |||||||||||
| 77 | |||||||||||
| 78 | # == METHODS == | ||||||||||
| 79 | # === encode === | ||||||||||
| 80 | # * encode($string [,$check]) | ||||||||||
| 81 | # * Encodes unicode hangul syllables (Perl internal string) | ||||||||||
| 82 | # into transliterated (romanized) string | ||||||||||
| 83 | 0 | ▶ | sub encode ($$;$) { | ||||||||
|
Subroutine
encode: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 84 | 0 | my ($obj, $str, $chk) = @_; | |||||||||
| 85 | 0 | my $tr = Encode::encode 'utf8', $mrr->encode($str, $chk); | |||||||||
| 86 | 0 | ▶ | $_[1] = '' if $chk; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | 0 | return $tr; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | # === decode === | ||||||||||
| 91 | # * decode($octets [,$check]) | ||||||||||
| 92 | # * Decodes transliteration into unicode hangul syllables (Perl internal string) | ||||||||||
| 93 | 0 | ▶ | sub decode ($$;$) { | ||||||||
|
Subroutine
decode: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 94 | 0 | my ($obj, $str, $chk) = @_; | |||||||||
| 95 | 0 | my $han = $mrr->decode(Encode::decode('utf8', $str), $chk); | |||||||||
| 96 | 0 | ▶ | $_[1] = '' if $chk; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | 0 | return $han; | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | # === cat_decode === | ||||||||||
| 101 | # * Needs to work with encoding pragma | ||||||||||
| 102 | # * cat_decode($destination, $octets, $offset, $terminator [,$check]) | ||||||||||
| 103 | |||||||||||
| 104 | |||||||||||
| 105 | 1 | 1; | |||||||||
| 106 | __END__ | ||||||||||