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)
| 5390 | |
| 5391 | |
| 5392 | def GetLineWidth(line): |
| 5393 | """Determines the width of the line in column positions. |
| 5394 | |
| 5395 | Args: |
| 5396 | line: A string, which may be a Unicode string. |
| 5397 | |
| 5398 | Returns: |
| 5399 | The width of the line in column positions, accounting for Unicode |
| 5400 | combining characters and wide characters. |
| 5401 | """ |
| 5402 | if isinstance(line, str): |
| 5403 | width = 0 |
| 5404 | for uc in unicodedata.normalize("NFC", line): |
| 5405 | if unicodedata.east_asian_width(uc) in ("W", "F"): |
| 5406 | width += 2 |
| 5407 | elif not unicodedata.combining(uc): |
| 5408 | # Issue 337 |
| 5409 | # https://mail.python.org/pipermail/python-list/2012-August/628809.html |
| 5410 | if (sys.version_info.major, sys.version_info.minor) <= (3, 2): |
| 5411 | # https://github.com/python/cpython/blob/2.7/Include/unicodeobject.h#L81 |
| 5412 | is_wide_build = sysconfig.get_config_var("Py_UNICODE_SIZE") >= 4 |
| 5413 | # https://github.com/python/cpython/blob/2.7/Objects/unicodeobject.c#L564 |
| 5414 | is_low_surrogate = 0xDC00 <= ord(uc) <= 0xDFFF |
| 5415 | if not is_wide_build and is_low_surrogate: |
| 5416 | width -= 1 |
| 5417 | |
| 5418 | width += 1 |
| 5419 | return width |
| 5420 | return len(line) |
| 5421 | |
| 5422 | |
| 5423 | def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state, error, cppvar=None): |
no outgoing calls
no test coverage detected