Skip to content

Instantly share code, notes, and snippets.

@spikeekips
Last active September 8, 2016 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save spikeekips/0a80b1079e4660d50dded81e351f00a8 to your computer and use it in GitHub Desktop.
Save spikeekips/0a80b1079e4660d50dded81e351f00a8 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
"""
# nfc2nfd.py
Simply convert nfc(ed) file to nfd(ed) file
Written by Spike^ekipS <spikeekips@gmail.com>
# Installation
1. save this gist to /usr/local/bin/nfc2nfd.py
1. run `$ chmod 755 /usr/local/bin/nfc2nfd.py
# Usage
If your filename is `input.txt`,
```
$ cat input.txt | nfc2nfd.py
```
or
```
$ nfc2nfd.py input.txt
```
"""
import sys
import select
import unicodedata
def usage():
print 'Usage: %s [filename]' % sys.argv[0]
target = None
if select.select([sys.stdin, ], [], [], 0.0)[0]:
target = sys.stdin.read()
else:
try:
target = file(sys.argv[1]).read()
except IndexError:
pass
if target is None:
usage()
sys.exit(1)
print unicodedata.normalize('NFC', unicode(target, 'utf-8')).encode('utf-8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment