MCPcopy Create free account
hub / github.com/alibaba/GraphScope / GetLineWidth

Function GetLineWidth

analytical_engine/misc/cpplint.py:4778–4807  ·  view source on GitHub ↗

Determines the width of the line in column positions. Args: line: A string, which may be a Unicode string. Returns: The width of the line in column positions, accounting for Unicode combining characters and wide characters.

(line)

Source from the content-addressed store, hash-verified

4776
4777
4778def GetLineWidth(line):
4779 """Determines the width of the line in column positions.
4780
4781 Args:
4782 line: A string, which may be a Unicode string.
4783
4784 Returns:
4785 The width of the line in column positions, accounting for Unicode
4786 combining characters and wide characters.
4787 """
4788 if isinstance(line, unicode):
4789 width = 0
4790 for uc in unicodedata.normalize('NFC', line):
4791 if unicodedata.east_asian_width(uc) in ('W', 'F'):
4792 width += 2
4793 elif not unicodedata.combining(uc):
4794 # Issue 337
4795 # https://mail.python.org/pipermail/python-list/2012-August/628809.html
4796 if (sys.version_info.major, sys.version_info.minor) <= (3, 2):
4797 # https://github.com/python/cpython/blob/2.7/Include/unicodeobject.h#L81
4798 is_wide_build = sysconfig.get_config_var("Py_UNICODE_SIZE") >= 4
4799 # https://github.com/python/cpython/blob/2.7/Objects/unicodeobject.c#L564
4800 is_low_surrogate = 0xDC00 <= ord(uc) <= 0xDFFF
4801 if not is_wide_build and is_low_surrogate:
4802 width -= 1
4803
4804 width += 1
4805 return width
4806 else:
4807 return len(line)
4808
4809
4810def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,

Callers 2

CheckBracesFunction · 0.85
CheckStyleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected