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 5151import string
5252import sys
5353import unicodedata
54+ import sysconfig
5455
5556try :
5657 xrange # Python 2
@@ -4291,6 +4292,16 @@ def GetLineWidth(line):
42914292 if unicodedata .east_asian_width (uc ) in ('W' , 'F' ):
42924293 width += 2
42934294 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+
42944305 width += 1
42954306 return width
42964307 else :
Original file line number Diff line number Diff line change @@ -321,6 +321,8 @@ def testGetLineWidth(self):
321321 self .assertEquals (0 , cpplint .GetLineWidth ('' ))
322322 self .assertEquals (10 , cpplint .GetLineWidth (u'x' * 10 ))
323323 self .assertEquals (16 , cpplint .GetLineWidth (u'都|道|府|県|支庁' ))
324+ self .assertEquals (5 + 13 + 9 , cpplint .GetLineWidth (
325+ u'd𝐱/dt' + u'f : t ⨯ 𝐱 → ℝ' + u't ⨯ 𝐱 → ℝ' ))
324326
325327 def testGetTextInside (self ):
326328 self .assertEquals ('' , cpplint ._GetTextInside ('fun()' , r'fun\(' ))
You can’t perform that action at this time.
0 commit comments