File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change 51
51
import string
52
52
import sys
53
53
import unicodedata
54
+ import sysconfig
54
55
55
56
try :
56
57
xrange # Python 2
@@ -4291,6 +4292,16 @@ def GetLineWidth(line):
4291
4292
if unicodedata .east_asian_width (uc ) in ('W' , 'F' ):
4292
4293
width += 2
4293
4294
elif not unicodedata .combining (uc ):
4295
+ # Issue 337
4296
+ # https://mail.python.org/pipermail/python-list/2012-August/628809.html
4297
+ if (sys .version_info .major , sys .version_info .minor ) <= (3 , 2 ):
4298
+ # https://github.com/python/cpython/blob/2.7/Include/unicodeobject.h#L81
4299
+ is_wide_build = sysconfig .get_config_var ("Py_UNICODE_SIZE" ) >= 4
4300
+ # https://github.com/python/cpython/blob/2.7/Objects/unicodeobject.c#L564
4301
+ is_low_surrogate = 0xDC00 <= ord (uc ) <= 0xDFFF
4302
+ if not is_wide_build and is_low_surrogate :
4303
+ width -= 1
4304
+
4294
4305
width += 1
4295
4306
return width
4296
4307
else :
Original file line number Diff line number Diff line change @@ -321,6 +321,8 @@ def testGetLineWidth(self):
321
321
self .assertEquals (0 , cpplint .GetLineWidth ('' ))
322
322
self .assertEquals (10 , cpplint .GetLineWidth (u'x' * 10 ))
323
323
self .assertEquals (16 , cpplint .GetLineWidth (u'都|道|府|県|支庁' ))
324
+ self .assertEquals (5 + 13 + 9 , cpplint .GetLineWidth (
325
+ u'd𝐱/dt' + u'f : t ⨯ 𝐱 → ℝ' + u't ⨯ 𝐱 → ℝ' ))
324
326
325
327
def testGetTextInside (self ):
326
328
self .assertEquals ('' , cpplint ._GetTextInside ('fun()' , r'fun\(' ))
You can’t perform that action at this time.
0 commit comments