Permalink
Browse files

fixed bug : doesn't work properly with East Asian Language

calculate string length as unicode type, not str type
  • Loading branch information...
1 parent 8db3e17 commit 4189dce16ecfb7a680b45333995eec9a0fdb844d choplin committed Oct 1, 2011
Showing with 12 additions and 2 deletions.
  1. +12 −2 ftplugin/rst_tables.vim
View
@@ -20,6 +20,7 @@ python << endpython
import vim
import re
import textwrap
+import unicodedata
from vim_bridge import bridged
@@ -160,8 +161,17 @@ def table_line(widths, header=False):
def get_field_width(field_text):
- return max(map(lambda s: len(s), field_text.split('\n')))
-
+ return max(map(get_string_width, field_text.split('\n')))
+
+def get_string_width(string):
+ width = 0
+ for char in list(string.decode('utf-8')):
+ eaw = unicodedata.east_asian_width(char)
+ if eaw == 'Na' or eaw == 'H':
+ width += 1
+ else:
+ width += 2
+ return width
def split_row_into_lines(row):
row = map(lambda field: field.split('\n'), row)

0 comments on commit 4189dce

Please sign in to comment.