W3C home > Mailing lists > Public > www-talk@w3.org > May to June 1995

Re: Automatic Filter for Accented Characters ?

From: Rainer Klute <klute@nads.de>
Date: Mon, 19 Jun 1995 17:59:10 +0200
Message-Id: <199506191559.RAA03212@heike.nads.de>
To: Jose Fernando Tepedino Martins <jftm@di.ufpe.br>
Cc: www-talk@www10.w3.org, "Rainer Klute" <klute@nads.de>
Jose Fernando Tepedino Martins <jftm@di.ufpe.br> in <9506182110.AA20081@di.ufpe.br>:
>   I have now a lot of documents with accented characters, and I love 
>them, because they make the text much more readable than using any other
>codification. I've been wondering if I really should run a transformation
>program for each HTML file I write before putting it in the WWW Server
>public area. What I mean is: 
>
>-> Is there a way to associate a filter to the WWW Server in order 
>   that it reads the HTML documents with 8-bit characters (with accented 
>   characters) and send a 7-bit (as &eacute;...) equivalent codification?

Here is something not quite what you asked for but hopefully
nevertheless useful. And it also converts the other way round.
Please excuse the crude interface and documentation but I hacked
this just for internal use.

Best regards
Rainer Klute

  Dipl.-Inform. Rainer Klute        NADS - Advertising on nets
  NADS GmbH
  Emil-Figge-Str. 80                Tel.: +49 231 9742570
D-44227 Dortmund                    Fax:  +49 231 9742571

            <http://www.nads.de/~klute/>




#!/usr/local/bin/perl

# Options:
#
# +iso:        convert to ISO 8859-1
# -iso:        convert to entity representation (default)
# +characters: convert characters outside ASCII
# -characters: don't convert characters outside ASCII (default)
# +html:       convert HTML special characters &, ", <, >
# -html:       don't convert HTML special characters &, ", <, > (default)

$characters = "no";
$html = "no";
$iso = "no";
for ($i = 0; $i <= $#ARGV; $i++)
{
    if ($ARGV[$i] =~ /^([+-])(.*)/)
    {
	$c = $1;
	splice (@ARGV, $i, 1);
	$i--;
	$_ = $2;
	{
	    /^c/ && ($characters = ($c eq "+" ? "yes" : "no"), last);
	    /^h/ && ($html       = ($c eq "+" ? "yes" : "no"), last);
	    /^i/ && ($iso        = ($c eq "+" ? "yes" : "no"), last);
	}
    };
};

@html = ('&', '&amp;',		# must be the first one
	 '<', '&lt;',
	 '>', '&gt;',
	 '"', '&quot;');

@characters = ('', '&aacute;',
	       '', '&Aacute;',
	       '', '&acirc;',
	       '', '&Acirc;',
	       '', '&agrave;',
	       '', '&Agrave;',
	       '', '&aring;',
	       '', '&Aring;',
	       '', '&atilde;',
	       '', '&Atilde;',
	       '', '&auml;',
	       '', '&Auml;',
	       '', '&aelig;',
	       '', '&AElig;',
	       '', '&ccedil;',
	       '', '&Ccedil;',
	       '', '&eth;',
	       '', '&ETH;',
	       '', '&eacute;',
	       '', '&Eacute;',
	       '', '&ecirc;',
	       '', '&Ecirc;',
	       '', '&egrave;',
	       '', '&Egrave;',
	       '', '&euml;',
	       '', '&Euml;',
	       '', '&iacute;',
	       '', '&Iacute;',
	       '', '&icirc;',
	       '', '&Icirc;',
	       '', '&igrave;',
	       '', '&Igrave;',
	       '', '&iuml;',
	       '', '&Iuml;',
	       '', '&ntilde;',
	       '', '&Ntilde;',
	       '', '&oacute;',
	       '', '&Oacute;',
	       '', '&ocirc;',
	       '', '&Ocirc;',
	       '', '&ograve;',
	       '', '&Ograve;',
	       '', '&oslash;',
	       '', '&Oslash;',
	       '', '&otilde;',
	       '', '&Otilde;',
	       '', '&ouml;',
	       '', '&Ouml;',
	       '', '&szlig;',
	       '', '&thorn;',
	       '', '&THORN;',
	       '', '&uacute;',
	       '', '&Uacute;',
	       '', '&ucirc;',
	       '', '&Ucirc;',
	       '', '&ugrave;',
	       '', '&Ugrave;',
	       '', '&uuml;',
	       '', '&Uuml;',
	       '', '&yacute;',
	       '', '&Yacute;',
	       '', '&yuml;');

while (<>)
{

    if ($iso eq "no")
    {
	if ($html eq "yes")
	{
	    for ($i = 0; $i <= $#html; $i += 2)
	    {
		s/$html[$i]/$html[$i+1]/eg;
	    };
	};
	
	if ($characters eq "yes")
	{
	    for ($i = 0; $i <= $#characters; $i += 2)
	    {
		s/$characters[$i]/$characters[$i+1]/eg;
	    };
	};
    }
    else
    {
	if ($html eq "yes")
	{
	    for ($i = 1; $i < $#html; $i += 2)
	    {
		s/$html[$i]/$html[$i-1]/eg;
	    };
	};
	
	if ($characters eq "yes")
	{
	    for ($i = 1; $i < $#characters; $i += 2)
	    {
		s/$characters[$i]/$characters[$i-1]/eg;
	    };
	};
    }

    print;
}
Received on Monday, 19 June 1995 12:05:36 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 27 October 2010 18:14:17 GMT