Anonymous avatar Anonymous committed e019245

* normalization (support for override files yet to come)

Comments (0)

Files changed (1)

src/uninormalize.py

 import unicodedata
 from itertools import imap
 import codecs
-from helpers import print_version
+from helpers import *
 
 def main():
     from optparse import OptionParser
-    parser = OptionParser()
-    parser.add_option("-v", "--version", help="print version and exit", default=False, action="store_true")
+    parser = OptionParser(usage="%prog [options] [[-n] NORM]")
+    parser.add_option("-V", "--version", help="print version and exit", default=False, action="store_true")
+    parser.add_option("-i", "--input", dest="input", help="read Unicode stream from FILE ('-' means stdin, this is the default)", metavar="FILE", default="-")
+    parser.add_option("--encoding", help="set input/output streams binary encoding ('utf-8' is the default)", default='utf-8')
+    parser.add_option("-n", "--normalization", help="use specific normalization as defined in Unicode Standard\nPossible values are NFC (default), NFKC, NFD, and NFKD",
+            metavar="NORM")
     
     run(*parser.parse_args())
+    parser.destroy()
 
 def run(options, args):
     if options.version:
         return print_version()
-    pass
+    if args:
+        options.normalization = args[0]
+        args = args[1:]
+    if not options.normalization:
+        options.normalization = 'NFC'
+    options.normalization = options.normalization.upper()
+    if options.normalization not in ('NFC', 'NFKC', 'NFD', 'NFKD'):
+        die("%s: unknown normalization %r", os.path.basename(sys.argv[0]), options.normalization)
+
+    for l in open_input(options):
+        print unicodedata.normalize(options.normalization, l).encode(options.encoding)
 
 if __name__ == "__main__":
     main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.