Created
April 12, 2012 02:39
-
-
Save moriyoshi/2364331 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# encoding: utf-8 | |
import unicodedata | |
import csv | |
import sys | |
wt = { 'W':2, 'A':2 } | |
encoding = 'UTF-8' | |
def len_in_eaw(s): | |
retval = 0 | |
for c in s: | |
retval += wt.get(unicodedata.east_asian_width(c), 1) | |
return retval | |
def main(): | |
rows = [] | |
mlen = [] | |
for cols in csv.reader(sys.stdin): | |
cols = [unicode(col, encoding) for col in cols] | |
rows.append(cols) | |
if len(mlen) < len(cols): | |
mlen += [0] * (len(cols) - len(mlen)) | |
for i, col in enumerate(cols): | |
mlen[i] = max(mlen[i], len_in_eaw(col)) | |
for cols in rows: | |
for i in range(0, len(mlen)): | |
print '-' * mlen[i], | |
for i in range(0, len(mlen)): | |
col = cols[i] if i < len(cols) else u'' | |
print (col + (u' ' * (mlen[i] - len_in_eaw(col)))).encode(encoding), | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment