Created
June 21, 2010 07:35
-
-
Save badp/446542 to your computer and use it in GitHub Desktop.
Put ligatures where possible. Save characters.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/bin/python3 | |
# -*- coding: utf-8 -*- | |
import sys | |
if sys.version_info < (3,): | |
raise Exception("This requires Python 3 to run. Sorry.") | |
ligatures = { "db": "ȸ", | |
"AE": "Æ", | |
"ae": "æ", | |
"OE": "Œ", | |
"oe": "œ", | |
"ue": "ᵫ", | |
"ff": "ff", | |
"IJ": "IJ", | |
"ij": "ij", | |
"fi": "fi", | |
"fl": "fl", | |
"ffi": "ffi", | |
"ffi": "ffi", | |
"ffi": "ffi", | |
"ffl": "ffl", | |
"ffi": "ffl", | |
"ffl": "ffl", | |
"ffl": "ffl", | |
"ft": "ſt", | |
"OI": "Ƣ", | |
"oi": "ƣ", | |
"IJ": "IJ", | |
"ij": "ij", | |
"qp": "ȹ", | |
"st": "st", | |
} | |
additional_ligatures = { "et": "&", | |
"SS": "ẞ", | |
"ss": "ß", | |
} | |
digraphs = { "DZ": "DZ", | |
"Dz": "Dz", | |
"dz": "dz", | |
"DŽ": "DŽ", | |
"Dž": "Dž", | |
"dž": "dž", | |
"LJ": "LJ", | |
"Lj": "Lj", | |
"lj": "lj", | |
"NJ": "NJ", | |
"Nj": "Nj", | |
"nj": "nj", | |
} | |
text = sys.stdin.read() | |
for replacement_list in [ligatures, digraphs]: | |
for letters, replacement in replacement_list.items(): | |
text = text.replace(letters, replacement) | |
sys.stdout.write(text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code is formatted to be best seen with elastic tabstops.