[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Forms: parsing accented chars



>At 14:26 11/04/96 -0400, "Stephane Jose" <jose.stephane@uqam.ca> wrote:

>Perl does *not* have any troubles parsing accented characters.
>"&eacute;". So you need a translation table, and a lot of lines like this:
>
>        s/=E9/&eacute;/g;

I've written this table for use in my interactive quiz program for
foreign language instruction.  Here's my routine for handling accents.
The last six or so substitutions are "dead key accents"  They
translate, for example, u" into a u with a diaresis over it; this is
useful if you expect users with browsers that don't handle iso-8859-1
input. 

sub Accents {
    local($value) = @_;
    study($value);
    $value =~ s/\300/&Agrave;/g;
    $value =~ s/\304/&Auml;/g;
    $value =~ s/\307/&Ccedil;/g;
    $value =~ s/\311/&Eacute;/g;
    $value =~ s/\321/&Ntilde;/g;
    $value =~ s/\326/&Ouml;/g;
    $value =~ s/\334/&Uuml;/g;
    $value =~ s/\337/&szlig;/g;    
    $value =~ s/\340/&agrave;/g;
    $value =~ s/\341/&aacute;/g;
    $value =~ s/\342/&acirc;/g;
    $value =~ s/\344/&auml;/g;
    $value =~ s/\347/&ccedil;/g;
    $value =~ s/\350/&egrave;/g;
    $value =~ s/\351/&eacute;/g;
    $value =~ s/\352/&ecirc;/g;
    $value =~ s/\354/&igrave;/g;
    $value =~ s/\355/&iacute;/g;
    $value =~ s/\356/&icirc;/g;
    $value =~ s/\357/&iuml;/g;
    $value =~ s/\361/&ntilde;/g;
    $value =~ s/\362/&ograve;/g;
    $value =~ s/\363/&oacute;/g;
    $value =~ s/\364/&ocirc;/g;
    $value =~ s/\366/&ouml;/g;
    $value =~ s/\371/&ugrave;/g;
    $value =~ s/\372/&uacute;/g;
    $value =~ s/\374/&uuml;/g;
    $value =~ s/([AEIOUaeio])'/&$1acute;/g;
    $value =~ s/\^([AEIOUaeiou])/&$1circ;/g;
    $value =~ s/`([AEIOUaeiou])/&$1grave;/g;
    $value =~ s/~([ANOano])/&$1tilde;/g;
    $value =~ s/:([AEIOUYaeiouy])/&$1uml;/g;
    $value =~ s/,([Cc])/&$1cedil;/g;
    $value =~ s/sss/&szlig;/g;
    return($value);
}