[Moscow.pm] Конвертация unicode символов в ascii

Lars Dɪᴇᴄᴋᴏᴡ 迪拉斯 daxim на cpan.org
Ср Июл 4 09:01:55 PDT 2012


> автоматической конвертации
> unicodных символов

По-чему? Я вообразю у тебя есть [XY problem](http://mywiki.wooledge.org/XyProblem).
Пожалуйста передай какаю задачу ты хочешь решить? Искать текст?

use utf8;
use Unicode::Collate qw();
my $c = Unicode::Collate->new(normalization => undef, level => 1, entry => <<'ENTRY');
0131;[.16B2.0020.0002.0069]
0259;[.1631.0020.0002.0065]
018F;[.1631.0020.0008.0045]
ENTRY

my $az = 'Əski dövr adlandırılan birinci dövr XIII əsrdən XVIII əsrə qədər '.
'olan dövrü, yeni adlandırıla bilən ikinci dövr isə XVIII əsrdən yaşadığımız '.
'günlərə qədər olan bir dövrü əhatə edir. Əski Azərbaycan dilində söz '.
'birləşmələrinin quruluşu daha çox ərəb və fars dillərinin sintaktik '.
'modelində olmuşdur: fəsli-gül (gül fəsli), tərki-təriqi-eşq (eşq təriqinin '.
'(yolunun) tərki), daxili-əhli-kamal (kamal əhlinə daxil)…';

for my $user_input (qw(adlandirilan Azerbaycan cox dovru ehate Eski gul qurulusu teriqinin yasadigimiz)) {
    if (my ($pos, $len) = $c->index($az, $user_input)) {
        printf "Found %s at position %d, length %d as %s\n",
            $user_input, $pos, $len, substr($az, $pos, $len);
    } else {
        print "Could not find $user_input.\n";
    }
}
__END__
Found adlandirilan at position 10, length 12 as adlandırılan
Found Azerbaycan at position 187, length 10 as Azərbaycan
Found cox at position 240, length 3 as çox
Found dovru at position 70, length 5 as dövrü
Found ehate at position 170, length 5 as əhatə
Found Eski at position 0, length 4 as Əski
Found gul at position 304, length 3 as gül
Found qurulusu at position 226, length 8 as quruluşu
Found teriqinin at position 343, length 9 as təriqinin
Found yasadigimiz at position 129, length 11 as yaşadığımız
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://mail.pm.org/pipermail/moscow-pm/attachments/20120704/24db2b44/attachment.bin>


Подробная информация о списке рассылки Moscow-pm