MCPcopy Create free account
hub / github.com/apache/mesos / GetLineWidth

Function GetLineWidth

support/cpplint.py:4279–4308  ·  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

4277
4278
4279def GetLineWidth(line):
4280 """Determines the width of the line in column positions.
4281
4282 Args:
4283 line: A string, which may be a Unicode string.
4284
4285 Returns:
4286 The width of the line in column positions, accounting for Unicode
4287 combining characters and wide characters.
4288 """
4289 if isinstance(line, unicode):
4290 width = 0
4291 for uc in unicodedata.normalize('NFC', line):
4292 if unicodedata.east_asian_width(uc) in ('W', 'F'):
4293 width += 2
4294 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
4305 width += 1
4306 return width
4307 else:
4308 return len(line)
4309
4310
4311def 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