From 4189dce16ecfb7a680b45333995eec9a0fdb844d Mon Sep 17 00:00:00 2001 From: choplin Date: Sat, 1 Oct 2011 20:17:49 +0900 Subject: fixed bug : doesn't work properly with East Asian Language calculate string length as unicode type, not str type --- ftplugin/rst_tables.vim | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ftplugin/rst_tables.vim b/ftplugin/rst_tables.vim index e042157..a77bafe 100644 --- a/ftplugin/rst_tables.vim +++ b/ftplugin/rst_tables.vim @@ -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) -- cgit v1.2.3