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)
| 5527 | |
| 5528 | |
| 5529 | def 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 | |
| 5560 | def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state, error, cppvar=None): |
no outgoing calls
no test coverage detected
searching dependent graphs…