@@ -1121,6 +1121,31 @@ def _get_formatted_html_string(self, options):
1121
1121
1122
1122
return self ._unicode ("\n " ).join (lines )
1123
1123
1124
+ ##############################
1125
+ # UNICODE WIDTH FUNCTIONS #
1126
+ ##############################
1127
+
1128
+ def _char_block_width (char ):
1129
+ char = ord (char )
1130
+ # Basic Latin, which is probably the most common case
1131
+ if char in range (0x0021 , 0x007e ):
1132
+ return 1
1133
+ # Chinese, Japanese, Korean (common)
1134
+ if char in range (0x4e00 , 0x9fff ):
1135
+ return 2
1136
+ # Combining?
1137
+ if unicodedata .combining (uni_chr (char )):
1138
+ return 0
1139
+ # Hiragana and Katakana
1140
+ if char in range (0x3040 , 0x309f ) or char in range (0x30a0 , 0x30ff ):
1141
+ return 2
1142
+ # Take a guess
1143
+ return 1
1144
+
1145
+ def _str_block_width (val ):
1146
+
1147
+ return sum (itermap (_char_block_width , val ))
1148
+
1124
1149
##############################
1125
1150
# TABLE FACTORIES #
1126
1151
##############################
@@ -1135,10 +1160,10 @@ def from_csv(fp, field_names = None):
1135
1160
if field_names :
1136
1161
table .field_names = field_names
1137
1162
else :
1138
- table .field_names = reader .next ()
1163
+ table .field_names = [ x . strip () for x in reader .next ()]
1139
1164
1140
1165
for row in reader :
1141
- table .add_row (row )
1166
+ table .add_row ([ x . strip () for x in row ] )
1142
1167
1143
1168
return table
1144
1169
@@ -1173,23 +1198,3 @@ def main():
1173
1198
1174
1199
if __name__ == "__main__" :
1175
1200
main ()
1176
-
1177
- def _char_block_width (char ):
1178
- # Basic Latin, which is probably the most common case
1179
- if char in range (0x0021 , 0x007e ):
1180
- return 1
1181
- # Chinese, Japanese, Korean (common)
1182
- if char in range (0x4e00 , 0x9fff ):
1183
- return 2
1184
- # Combining?
1185
- if unicodedata .combining (uni_chr (char )):
1186
- return 0
1187
- # Hiragana and Katakana
1188
- if char in range (0x3040 , 0x309f ):
1189
- return 2
1190
- # Take a guess
1191
- return 1
1192
-
1193
- def _str_block_width (val ):
1194
-
1195
- return sum (map (_char_block_width , map (ord , val )))
0 commit comments