wiki.pl: Port some fixes from upstream
[Orgmuse.git] / utf-8.pl
blob48d0911cf74249792d69f2a36a8bf1235a604610
1 #! /usr/bin/perl
2 # Copyright (C) 2004 Alex Schroeder <alex@emacswiki.org>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the
16 # Free Software Foundation, Inc.
17 # 59 Temple Place, Suite 330
18 # Boston, MA 02111-1307 USA
20 use CGI qw/:standard/;
21 use CGI::Carp qw(fatalsToBrowser);
22 use Encode;
24 sub translate {
25 my $str = shift;
26 $str = encode('utf-8', decode('latin-1', $str));
27 my @letters = split(//, $str);
28 my @safe = ('a' .. 'z', 'A' .. 'Z', '0' .. '9', '-', '_', '.', '!', '~', '*', "'", '(', ')',
29 ':', '/', '?', ';', '&');
30 foreach my $letter (@letters) {
31 my $pattern = quotemeta($letter);
32 if (not grep(/$pattern/, @safe)) {
33 $letter = uc(sprintf("%%%02x", ord($letter)));
36 return join('', @letters);
39 if (not param('url')) {
40 print header(),
41 start_html('Latin-1 to UTF-8 Escapes'),
42 h1('Latin-1 to UTF-8 Escapes'),
43 p('Translates URLs containing URL-encoded Latin-1 to ',
44 'URLs containing URL-encoded UTF-8 and redirects to it.'),
45 start_form(-method=>'GET'),
46 p('URL: ', textfield('url', '', 70)),
47 p(submit()),
48 end_form(),
49 end_html();
50 exit;
53 my $str = param('url');
55 print redirect(translate($str));
57 # print $str, "\n";
58 # print translate($str), "\n";
60 # perl latin-1.pl url=http://www.emacswiki.org/cgi-bin/community/LangueFran%E7aise