Permalink
Browse files

Add transliteration methods

  • Loading branch information...
1 parent 0300db8 commit 471755762fd3c9e1bd8d82c9dc22b028577267bb @ctfouts ctfouts committed Mar 22, 2012
Showing with 22 additions and 0 deletions.
  1. +4 −0 lib/Xape/Charset.pm
  2. +15 −0 lib/Xape/Enumerator.pm
  3. +3 −0 t/001-enum.t
View
@@ -10,6 +10,10 @@ method lookup($in) {
return $self->charmap->{$in} // $self->charmap->{$self->xlitmap->{uc($in)}};
}
+method xlit_lookup($in) {
+ return $self->xlitmap->{uc($in)};
+}
+
no Any::Moose;
1;
View
@@ -33,6 +33,21 @@ method sum(Str $input) {
return $sum;
}
+method xlit(Str $input) {
+ my @words = split /\b/, $input;
+ my @outwords;
+ for my $word (@words) {
+ $word =~ s/\s//g;
+ next unless $word;
+ my @chars = split '', $word;
+ my $output = '';
+ $output .= $self->charset->xlit_lookup($_) // '' for (@chars);
+ push @outwords, $output;
+ }
+ return join ' ', @outwords;
+}
+
__PACKAGE__->meta->make_immutable;
+no Any::Moose;
1;
View
@@ -39,4 +39,7 @@ 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)';
+is $enum->xlit('IHVH'), "\x{5d9}\x{5d4}\x{5d5}\x{5d4}", 'Xlit';
+is $enum->xlit('IHVH NCW'), "\x{5d9}\x{5d4}\x{5d5}\x{5d4} \x{5e0}\x{5d7}\x{5e9}", 'Xlit with spaces';
+
done_testing;

0 comments on commit 4717557

Please sign in to comment.