diff options
author | Tomaz Solc <avian@toybox.zemanta.com> | 2008-09-05 16:51:19 +0200 |
---|---|---|
committer | Tomaz Solc <avian@toybox.zemanta.com> | 2008-09-05 16:51:19 +0200 |
commit | b2cedd05e3ce012098c23fbb263dc382ac45a302 (patch) | |
tree | 9b95fa5a01a64e0cab8c34f8ea4744f786eb0875 /perl2python.pl | |
download | unidecode-b2cedd05e3ce012098c23fbb263dc382ac45a302.tar.gz |
Initial import.
Diffstat (limited to 'perl2python.pl')
-rw-r--r-- | perl2python.pl | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/perl2python.pl b/perl2python.pl new file mode 100644 index 0000000..d512a40 --- /dev/null +++ b/perl2python.pl @@ -0,0 +1,45 @@ +use Getopt::Long; + +my $input = "."; +my $output = "."; + +$result = GetOptions("input=s" => \$input, + "output=s" => \$output); + +sub python_escape { + my $x = shift; + + return '' unless defined($x); + + $x =~ s/\\/\\\\/gs; + $x =~ s/'/\\'/gs; + $x =~ s/([\x00-\x1f])/sprintf("\\x%02x", ord($1))/ges; + + return $x; +} + +push(@INC, $input); + +my $n; +for($n = 0; $n < 256; $n++) { + + eval( sprintf("require x%02x;\n", $n) ); + + next unless( $#{$Text::Unidecode::Char[$n]} >= 0 ); + + open(PYTHON, sprintf(">%s/x%02x.py", $output, $n)); + print PYTHON "data = ("; + + my $first = 1; + for my $t (@{$Text::Unidecode::Char[$n]}) { + if( $first ) { + $first = 0; + } else { + print PYTHON ", "; + } + print PYTHON "'", &python_escape($t), "'"; + } + + print PYTHON ")\n"; + close(PYTHON) +} |