Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Lowercase and normalize a unicode string

by mugwumpjism (Hermit)
on Nov 02, 2010 at 03:40 UTC ( #868924=perlquestion: print w/ replies, xml ) Need Help??
mugwumpjism has asked for the wisdom of the Perl Monks concerning the following question:

Is there an easy way to normalize and lowercase a unicode string? This works for probably most Latin languages:
use Unicode::Normalize; my $lower_nfc = NFC(lc(NFD($string)));
However this doesn't work for, say, Greek. It seems that the Perl Unicode API would require this:
use Unicode::UCD qw(charinfo); use Unicode::Normalize; my $nfd_string = NFD($string); $nfd_string =~ s{(\p{Lu})}{chr(hex(charinfo(ord($1))->{lower}))}ge; my $nfc_string = NFC($nfd_string);
Surely there's an easier way...
$h=$ENV{HOME};my@q=split/\n\n/,`cat $h/.quotes`;$s="$h/." ."signature";$t=`cat $s`;print$t,"\n",$q[rand($#q)],"\n";

Comment on Lowercase and normalize a unicode string
Select or Download Code
Re: Lowercase and normalize a unicode string
by ikegami (Pope) on Nov 02, 2010 at 04:51 UTC

    lc alone should do. You shouldn't have to use normalize, and it should work for all scripts. Make sure you've decoded the text.

    If you're unlucky, you may have to use one of the following:

    utf8::upgrade($s); lc($s)
    or
    use feature qw( unicode_strings ); lc($s)

    If you're still have problems, please provide a sample string. Preferably using

    use Data::Dumper; local $Data::Dumper::Useqq = 1; print(Dumper($s));
    or
    use Devel::Peek; Dump($s);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://868924]
Approved by McDarren
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2014-07-26 09:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls