| 1 | # Encoding of Korean: SKATS (Standard Korean Alphabet Transliteration System) | ||||||||||
| 2 | |||||||||||
| 3 | # $Id: SKATS.pm,v 1.7 2007/11/29 14:25:31 you Exp $ | ||||||||||
| 4 | |||||||||||
| 5 | package Encode::Korean::SKATS; | ||||||||||
| 6 | |||||||||||
| 7 | 1 | our $VERSION = do { q$Revision: 1.7 $ =~ /\d+\.(\d+)/; sprintf "%.2f", $1 / 100 }; | |||||||||
| 8 | |||||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | use 5.008008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 1 | ▶ | use Encode::Encoding; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 1 | ▶ | use base qw(Encode::Encoding); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 1 | __PACKAGE__->Define(qw/skats/); | |||||||||
| 19 | |||||||||||
| 20 | 1 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 1 | require Encode; | |||||||||
| 22 | 1 | Encode->export_to_level(1,@_); | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | # == RULES == | ||||||||||
| 27 | 1 | ▶ | use Encode::Korean::TransliteratorGenerator; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 1 | my $skats = Encode::Korean::TransliteratorGenerator->new(); | |||||||||
| 29 | |||||||||||
| 30 | 1 | $skats->consonants(qw(L LL F B BB V M W WW G GG K P PP C X Z O J)); | |||||||||
| 31 | 1 | $skats->vowels(qw(E EU I US T TU S SU A AE AEU AU N H HT HTU HU R D DU U)); | |||||||||
| 32 | #$skats->el('l'); | ||||||||||
| 33 | #$skats->ell('ll'); | ||||||||||
| 34 | 1 | $skats->naught(''); | |||||||||
| 35 | 1 | $skats->sep(' '); | |||||||||
| 36 | 1 | $skats->make(); | |||||||||
| 37 | |||||||||||
| 38 | 1 | $skats->enmode('greedy'); | |||||||||
| 39 | 1 | $skats->demode('greedy'); | |||||||||
| 40 | |||||||||||
| 41 | |||||||||||
| 42 | # == MODES == | ||||||||||
| 43 | 0 | ▶ | sub enmode { | ||||||||
|
Subroutine
enmode: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 44 | 0 | my $class = shift; | |||||||||
| 45 | 0 | my($mode) = @_; | |||||||||
| 46 | 0 | $skats->enmode($mode); | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 0 | ▶ | sub demode { | ||||||||
|
Subroutine
demode: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 50 | 0 | my $class = shift; | |||||||||
| 51 | 0 | my($mode) = @_; | |||||||||
| 52 | 0 | $skats->demode($mode); | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | |||||||||||
| 56 | # == METHODS == | ||||||||||
| 57 | # === encode === | ||||||||||
| 58 | # * encode($string [,$check]) | ||||||||||
| 59 | # * Encodes unicode hangul syllables (Perl internal string) | ||||||||||
| 60 | # into transliterated (romanized) string | ||||||||||
| 61 | 0 | ▶ | sub encode ($$;$) { | ||||||||
|
Subroutine
encode: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 62 | 0 | my ($obj, $str, $chk) = @_; | |||||||||
| 63 | 0 | my $tr; | |||||||||
| 64 | 0 | my @word = split(/([ ]+)/, $str); | |||||||||
| 65 | 0 | foreach (@word) { | |||||||||
| 66 | 0 | ▶ | if ($_ =~ m/([ ]+)/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 0 | $tr = $tr . $1 . ' '; | |||||||||
| 68 | } else { | ||||||||||
| 69 | 0 | $tr = $tr . $skats->encode($_, $chk); | |||||||||
| 70 | } | ||||||||||
| 71 | } | ||||||||||
| 72 | 0 | ▶ | $_[1] = '' if $chk; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 0 | return $tr; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | # | ||||||||||
| 77 | # === decode === | ||||||||||
| 78 | # * decode($octets [,$check]) | ||||||||||
| 79 | # * Decodes transliteration into unicode hangul syllables (Perl internal string) | ||||||||||
| 80 | 0 | ▶ | sub decode ($$;$) { | ||||||||
|
Subroutine
decode: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 81 | 0 | my ($obj, $str, $chk) = @_; | |||||||||
| 82 | 0 | my $han; | |||||||||
| 83 | 0 | my @word = split(/([ ][ ]+)/, $str); | |||||||||
| 84 | 0 | foreach (@word) { | |||||||||
| 85 | 0 | ▶ | if ($_ =~ m/[ ]([ ]+)/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 0 | $han = $han . $1; | |||||||||
| 87 | } else { | ||||||||||
| 88 | 0 | $han = $han . $skats->decode($_, $chk); | |||||||||
| 89 | } | ||||||||||
| 90 | } | ||||||||||
| 91 | 0 | ▶ | $_[1] = '' if $chk; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | 0 | return $han; | |||||||||
| 93 | |||||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | # === cat_decode === | ||||||||||
| 97 | # * Needs to work with encoding pragma | ||||||||||
| 98 | # * cat_decode($destination, $octets, $offset, $terminator [,$check]) | ||||||||||
| 99 | |||||||||||
| 100 | |||||||||||
| 101 | 1 | 1; | |||||||||
| 102 | __END__ | ||||||||||