Update and clean Tomato RAF files
[tomato.git] / release / src / router / nginx / contrib / unicode2nginx / unicode-to-nginx.pl
blobdaaf354a830313e088fdc196727b071d720d4873
1 #!/usr/bin/perl -w
3 # Convert unicode mappings to nginx configuration file format.
5 # You may find useful mappings in various places, including
6 # unicode.org official site:
8 # http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1251.TXT
9 # http://www.unicode.org/Public/MAPPINGS/VENDORS/MISC/KOI8-R.TXT
11 # Needs perl 5.6 or later.
13 # Written by Maxim Dounin, mdounin@rambler-co.ru
15 ###############################################################################
17 require 5.006;
19 while (<>) {
20 # Skip comments and empty lines
22 next if /^#/;
23 next if /^\s*$/;
24 chomp;
26 # Convert mappings
28 if (/^\s*0x(..)\s*0x(....)\s*(#.*)/) {
29 # Mapping <from-code> <unicode-code> "#" <unicode-name>
30 my $cs_code = $1;
31 my $un_code = $2;
32 my $un_name = $3;
34 # Produce UTF-8 sequence from character code;
36 my $un_utf8 = join('', map { sprintf("%02X", $_) } unpack("C*", pack("U", hex($un_code))));
38 print " $cs_code $un_utf8 ; $un_name\n";
40 } else {
41 warn "Unrecognized line: '$_'";
45 ###############################################################################