11import os , re
22
3+ # this python script generates the unidecoder-decodemap.txt file
4+ # from the original python source. to make it run, you need
5+ # to download this directory from the original repository:
6+ # https://github.com/avian2/unidecode/tree/master/unidecode
7+ # and extract it in a folder named "py-codes"
8+ # when run, it will generate a file named unidecoder-decodemap.txt
9+ # that must be copied in the assets folder.
10+ # this file will be included in the assembly and used in the static
11+ # constructor of Unidecoder class.
12+
313d = "py-codes" # https://github.com/avian2/unidecode/tree/master/unidecode
414print ("working..." )
515
6- fp = open ("Unidecoder.Characters.cs" , "w" )
7- fp .write ('''/*
8- COPYRIGHT
9-
10- Character transliteration tables:
11-
12- Copyright 2001, Sean M. Burke <sburke@cpan.org>, all rights reserved.
13-
14- Python code:
15-
16- Copyright 2009, Tomaz Solc <tomaz@zemanta.com>
17-
18- The programs and documentation in this dist are distributed in the
19- hope that they will be useful, but without any warranty; without even
20- the implied warranty of merchantability or fitness for a particular
21- purpose.
22-
23- This library is free software; you can redistribute it and/or modify
24- it under the same terms as Perl.
25- */
26-
27- /*
28- Don't edit, this code is generated.
29- */
30-
31- using System;
32- using System.Collections.Generic;
33-
34- namespace Unidecode.NET
35- {
36- public static partial class Unidecoder
37- {
38- private static readonly Dictionary<int, string[]> characters;
39-
40- static Unidecoder()
41- {
42- characters = new Dictionary<int, string[]> {
43- ''' )
44-
16+ fp = open ("unidecoder-decodemap.txt" , "w" )
4517
4618def formatch (ch , cc ):
4719 ch = ch .replace ("\r " , "" )
4820 ch = ch .replace ("\\ " , "\\ \\ " )
4921 ch = ch .replace ("\" " , "\\ \" " )
50- ch = ch .replace ("\n " , '"+Environment.NewLine+ "' )
22+ ch = ch .replace ("\n " , '"\\ n "' )
5123 return ch if cc > 31 else "\\ u" + ('%x' % cc ).rjust (4 , '0' )
5224
53-
5425for file in [file for file in os .listdir (d ) if not file in ["." , ".." ]]:
5526 m = re .search ('x(.{3})\.py$' , file )
5627 if m :
@@ -61,21 +32,18 @@ def formatch(ch, cc):
6132 data += (fill ,)* missing
6233 assert len (data ) == 256
6334 c = 0
64- num = int (m .group (1 ), 16 ) * 256
65- fp .write (' {%s /*%s %s*/, new[]{\n ' % (int (m .group (1 ), 16 ), num , m .group (1 )))
35+ idx = int (m .group (1 ), 16 )
36+ num = idx * 256
37+ fp .write ('%3s\t ' % (idx ))
6638 for ch in data :
67- fp .write ('"%s" /*%s*/%s ' % (
68- formatch (ch , num + c ),
69- ("%x" % (num + c )).rjust (4 , '0' ),
70- "," if c < 255 else "" ))
39+ if ch is None :
40+ fp .write ('""' );
41+ else :
42+ fp .write ('"%s"' % (formatch (ch , num + c )))
43+ if c < 255 :
44+ fp .write ('\t ' )
7145 c = c + 1
72- fp .write ('}}, \n \n ' )
46+ fp .write ('\n ' )
7347
74- fp .write (
75- ''' };
76- }
77- }
78- }
79- ''' )
8048print ("converted!" )
8149
0 commit comments