Permalink
Browse files

Add transliteration support

  • Loading branch information...
1 parent 4bdc730 commit 0300db830d1b67f5b76e85282832b4d8c41646f8 @ctfouts ctfouts committed Mar 22, 2012
Showing with 36 additions and 1 deletion.
  1. +2 −1 lib/Xape/Charset.pm
  2. +31 −0 lib/Xape/Charset/he.pm
  3. +3 −0 t/001-enum.t
View
@@ -6,7 +6,8 @@ use Method::Signatures;
requires 'charmap';
method lookup($in) {
- return $self->charmap->{$in};
+ no warnings qw(uninitialized);
+ return $self->charmap->{$in} // $self->charmap->{$self->xlitmap->{uc($in)}};
}
no Any::Moose;
View
@@ -38,6 +38,37 @@ has 'charmap' => (
},
);
+has 'xlitmap' => (
+ is => 'ro',
+ isa => 'HashRef',
+ default => sub {
+ return {
+ 'A' => "\x{5d0}",
+ 'B' => "\x{5d1}",
+ 'G' => "\x{5d2}",
+ 'D' => "\x{5d3}",
+ 'H' => "\x{5d4}",
+ 'V' => "\x{5d5}",
+ 'Z' => "\x{5d6}",
+ 'C' => "\x{5d7}",
+ 'T' => "\x{5d8}",
+ 'I' => "\x{5d9}",
+ 'K' => "\x{5db}",
+ 'L' => "\x{5dc}",
+ 'M' => "\x{5de}",
+ 'N' => "\x{5e0}",
+ 'S' => "\x{5e1}",
+ 'O' => "\x{5e2}",
+ 'P' => "\x{5e4}",
+ 'J' => "\x{5e6}",
+ 'Q' => "\x{5e7}",
+ 'R' => "\x{5e8}",
+ 'W' => "\x{5e9}",
+ 'X' => "\x{5ea}",
+ };
+ },
+);
+
with 'Xape::Charset';
__PACKAGE__->meta->make_immutable;
View
@@ -33,7 +33,10 @@ $enum = Xape::Enumerator->new('he');
isa_ok $enum, 'Xape::Enumerator';
is $enum->sum("\x{5d0}"), 1, 'Single sum';
+is $enum->sum('A'), 1, 'Single sum (xlit)';
is $enum->sum("\x{5d0}\x{5ea}"), 401, 'Multiple sum';
+is $enum->sum('AX'), 401, 'Multiple sum (xlit)';
is $enum->sum("\x{5d0} \x{5ea} \x{5da}"), 421, 'Ignore space';
+is $enum->sum('A X K'), 421, 'Ignore space (xlit)';
done_testing;

0 comments on commit 0300db8

Please sign in to comment.