Lingua::RU::Jcuken - Conversion between QWERTY and JCUKEN keys in Russian


Lingua-RU-Jcuken documentation Contained in the Lingua-RU-Jcuken distribution.

Index


Code Index:

NAME

Top

Lingua::RU::Jcuken -- Conversion between QWERTY and JCUKEN keys in Russian

SYNOPSIS

Top

 use Lingua::RU::Jcuken qw/ jcu2qwe qwe2jcu /;

 print qwe2jcu('qwerty', 'koi8-r'); # prints "jcuken" in koi8-r

DESCRIPTION

Top

Lingua::RU::Jcuken can be used for conversion between two layouts on Russian keyboards.

METHODS

Top

jcu2qwe ( $string, [ $encoding ])

This method converts $string from Jcuken to Qwerty.

Optional $encoding parameter allows to specify $string's encoding (default is 'windows-1251')

qwe2jcu ( $string, [ $encoding ])

This method converts $string from Qwerty to Jcuken.

Optional $encoding parameter allows to specify result encoding (default is 'windows-1251'). It is also used as $string encoding if you have cyrillic in it.

AUTHORS

Top

Serguei Trouchelle <stro@railways.dp.ua>

COPYRIGHT

Top


Lingua-RU-Jcuken documentation Contained in the Lingua-RU-Jcuken distribution.
# Lingua/RU/Jcuken.pm
#
# Copyright (c) 2006-2008 Serguei Trouchelle. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.

# History:
#  1.04  2008/02/26 use Encode instead of Text::Iconv
#  1.03  2007/02/04 Quality update (Test::Pod, Test::Pod::Coverage)
#  1.02  2006/11/15 Fixed problem with undefined encoding in qwe2jcu
#  1.01  2006/11/15 Initial revision

package Lingua::RU::Jcuken;

require Exporter;
use Config;

use strict;
use warnings;

use Encode;

our @EXPORT      = qw/ /;
our @EXPORT_OK   = qw/ jcu2qwe qwe2jcu /;
our %EXPORT_TAGS = qw / /;
our @ISA = qw/Exporter/;

our $VERSION = "1.04";

my $table = q!1 1
q é
w ö
e ó
r ê
t å
y í
u ã
i ø
o ù
p ç
[ õ
] ú
a ô
s û
d â
f à
g ï
h ð
j î
k ë
l ä 
; æ
' ý
z ÿ
x ÷
c ñ
v ì
b è
n ò
m ü
, á
. þ
/ .
` ¸
Q É
W Ö
E Ó
R Ê
T Å
Y Í
U Ã
I Ø
O Ù
P Ç
{ Õ
} Ú
A Ô
S Û
D Â
F À
G Ï
H Ð
J Î
K Ë
L Ä
: Æ
" Ý
Z ß
X ×
C Ñ
V Ì
B È
N Ò
M Ü
< Á
> Þ
? .
~ ¨
2 2!;

our %qwe2jcu = split /\s+/, $table;
our %jcu2qwe = reverse split /\s+/, $table;

sub jcu2qwe {
  my $val = shift;
  my $enc = shift;
  Encode::from_to($val, $enc, 'windows-1251') if $enc;
  my $res = '';
  foreach (split //, $val) {
    $_ = $jcu2qwe{$_} if $jcu2qwe{$_};
    $res .= $_;
  }
  return $res;
}

sub qwe2jcu {
  my $val = shift;
  my $enc = shift;
  Encode::from_to($val, $enc, 'windows-1251') if $enc;
  $enc = 'windows-1251' unless $enc;
  my $res = '';
  foreach (split //, $val) {
    $_ = $qwe2jcu{$_} if $qwe2jcu{$_};
    Encode::from_to($_, 'windows-1251', $enc);
    $res .= $_;
  }
  return $res;
}

1;