diff options
Diffstat (limited to 'cpplint/cpplint.py')
-rwxr-xr-x | cpplint/cpplint.py | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/cpplint/cpplint.py b/cpplint/cpplint.py index 53dbe81..6c839b4 100755 --- a/cpplint/cpplint.py +++ b/cpplint/cpplint.py @@ -51,6 +51,12 @@ import sre_compile import string import sys import unicodedata +import sysconfig + +try: + xrange # Python 2 +except NameError: + xrange = range # Python 3 _USAGE = """ @@ -569,7 +575,7 @@ def ProcessHppHeadersOption(val): # Automatically append to extensions list so it does not have to be set 2 times _valid_extensions.update(_hpp_headers) except ValueError: - PrintUsage('Header extensions must be comma seperated list.') + PrintUsage('Header extensions must be comma separated list.') def IsHeaderExtension(file_extension): return file_extension in _hpp_headers @@ -1846,8 +1852,8 @@ def GetHeaderGuardCPPVariable(filename): PathSplitToList(_root)) if _root_debug: - sys.stderr.write("_root lstrip (maybe_path=%s, file_path_from_root=%s," + - " _root=%s)\n" %(maybe_path, file_path_from_root, _root)) + sys.stderr.write(("_root lstrip (maybe_path=%s, file_path_from_root=%s," + + " _root=%s)\n") %(maybe_path, file_path_from_root, _root)) if maybe_path: return os.path.join(*maybe_path) @@ -1860,8 +1866,8 @@ def GetHeaderGuardCPPVariable(filename): PathSplitToList(root_abspath)) if _root_debug: - sys.stderr.write("_root prepend (maybe_path=%s, full_path=%s, " + - "root_abspath=%s)\n" %(maybe_path, full_path, root_abspath)) + sys.stderr.write(("_root prepend (maybe_path=%s, full_path=%s, " + + "root_abspath=%s)\n") %(maybe_path, full_path, root_abspath)) if maybe_path: return os.path.join(*maybe_path) @@ -3277,8 +3283,8 @@ def CheckSpacing(filename, clean_lines, linenum, nesting_state, error): line = clean_lines.elided[linenum] # You shouldn't have spaces before your brackets, except maybe after - # 'delete []' or 'return []() {};' - if Search(r'\w\s+\[', line) and not Search(r'(?:delete|return)\s+\[', line): + # 'delete []', 'return []() {};', or 'auto [abc, ...] = ...;'. + if Search(r'\w\s+\[', line) and not Search(r'(?:auto&?|delete|return)\s+\[', line): error(filename, linenum, 'whitespace/braces', 5, 'Extra space before [') @@ -4286,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: @@ -6188,7 +6204,7 @@ def ParseArguments(args): try: _valid_extensions = set(val.split(',')) except ValueError: - PrintUsage('Extensions must be comma seperated list.') + PrintUsage('Extensions must be comma separated list.') elif opt == '--headers': ProcessHppHeadersOption(val) |