MCPcopy Create free account
hub / github.com/4paradigm/OpenMLDB / GetLineWidth

Function GetLineWidth

steps/cpplint.py:4788–4817  ·  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

4786
4787
4788def GetLineWidth(line):
4789 """Determines the width of the line in column positions.
4790
4791 Args:
4792 line: A string, which may be a Unicode string.
4793
4794 Returns:
4795 The width of the line in column positions, accounting for Unicode
4796 combining characters and wide characters.
4797 """
4798 if isinstance(line, unicode):
4799 width = 0
4800 for uc in unicodedata.normalize('NFC', line):
4801 if unicodedata.east_asian_width(uc) in ('W', 'F'):
4802 width += 2
4803 elif not unicodedata.combining(uc):
4804 # Issue 337
4805 # https://mail.python.org/pipermail/python-list/2012-August/628809.html
4806 if (sys.version_info.major, sys.version_info.minor) <= (3, 2):
4807 # https://github.com/python/cpython/blob/2.7/Include/unicodeobject.h#L81
4808 is_wide_build = sysconfig.get_config_var("Py_UNICODE_SIZE") >= 4
4809 # https://github.com/python/cpython/blob/2.7/Objects/unicodeobject.c#L564
4810 is_low_surrogate = 0xDC00 <= ord(uc) <= 0xDFFF
4811 if not is_wide_build and is_low_surrogate:
4812 width -= 1
4813
4814 width += 1
4815 return width
4816 else:
4817 return len(line)
4818
4819
4820def 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