MCPcopy Index your code
hub / github.com/nodejs/node / GetLineWidth

Function GetLineWidth

tools/cpplint.py:5529–5557  ·  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

5527
5528
5529def GetLineWidth(line):
5530 """Determines the width of the line in column positions.
5531
5532 Args:
5533 line: A string, which may be a Unicode string.
5534
5535 Returns:
5536 The width of the line in column positions, accounting for Unicode
5537 combining characters and wide characters.
5538 """
5539 if isinstance(line, str):
5540 width = 0
5541 for uc in unicodedata.normalize("NFC", line):
5542 if unicodedata.east_asian_width(uc) in ("W", "F"):
5543 width += 2
5544 elif not unicodedata.combining(uc):
5545 # Issue 337
5546 # https://mail.python.org/pipermail/python-list/2012-August/628809.html
5547 if (sys.version_info.major, sys.version_info.minor) <= (3, 2):
5548 # https://github.com/python/cpython/blob/2.7/Include/unicodeobject.h#L81
5549 is_wide_build = sysconfig.get_config_var("Py_UNICODE_SIZE") >= 4
5550 # https://github.com/python/cpython/blob/2.7/Objects/unicodeobject.c#L564
5551 is_low_surrogate = 0xDC00 <= ord(uc) <= 0xDFFF
5552 if not is_wide_build and is_low_surrogate:
5553 width -= 1
5554
5555 width += 1
5556 return width
5557 return len(line)
5558
5559
5560def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state, error, cppvar=None):

Callers 2

CheckBracesFunction · 0.85
CheckStyleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…