diff options
author | Mmanu Chaturvedi <mmanu.chaturvedi@kitware.com> | 2018-04-05 12:41:28 -0400 |
---|---|---|
committer | Mmanu Chaturvedi <mmanu.chaturvedi@kitware.com> | 2018-04-05 12:41:28 -0400 |
commit | b280a7312455e0310173a60673076ecc4b077290 (patch) | |
tree | adac193629bab852664f0b4313179b865c9629f6 | |
parent | 5508c2f7dfaba43b30d413c943560476c2e5a46c (diff) | |
download | google-styleguide-b280a7312455e0310173a60673076ecc4b077290.tar.gz |
Fix Issue 337
-rwxr-xr-x | cpplint/cpplint.py | 11 | ||||
-rwxr-xr-x | cpplint/cpplint_unittest.py | 2 |
2 files changed, 13 insertions, 0 deletions
diff --git a/cpplint/cpplint.py b/cpplint/cpplint.py index 8e07cab..fb34e11 100755 --- a/cpplint/cpplint.py +++ b/cpplint/cpplint.py @@ -51,6 +51,7 @@ import sre_compile import string import sys import unicodedata +import sysconfig try: xrange # Python 2 @@ -4291,6 +4292,16 @@ def GetLineWidth(line): if unicodedata.east_asian_width(uc) in ('W', 'F'): width += 2 elif not unicodedata.combining(uc): + # Issue 337 + # https://mail.python.org/pipermail/python-list/2012-August/628809.html + if (sys.version_info.major, sys.version_info.minor) <= (3, 2): + # https://github.com/python/cpython/blob/2.7/Include/unicodeobject.h#L81 + is_wide_build = sysconfig.get_config_var("Py_UNICODE_SIZE") >= 4 + # https://github.com/python/cpython/blob/2.7/Objects/unicodeobject.c#L564 + is_low_surrogate = 0xDC00 <= ord(uc) <= 0xDFFF + if not is_wide_build and is_low_surrogate: + width -= 1 + width += 1 return width else: diff --git a/cpplint/cpplint_unittest.py b/cpplint/cpplint_unittest.py index b3c7725..6087d8f 100755 --- a/cpplint/cpplint_unittest.py +++ b/cpplint/cpplint_unittest.py @@ -321,6 +321,8 @@ class CpplintTest(CpplintTestBase): self.assertEquals(0, cpplint.GetLineWidth('')) self.assertEquals(10, cpplint.GetLineWidth(u'x' * 10)) self.assertEquals(16, cpplint.GetLineWidth(u'都|道|府|県|支庁')) + self.assertEquals(5 + 13 + 9, cpplint.GetLineWidth( + u'd𝐱/dt' + u'f : t ⨯ 𝐱 → ℝ' + u't ⨯ 𝐱 → ℝ')) def testGetTextInside(self): self.assertEquals('', cpplint._GetTextInside('fun()', r'fun\(')) |