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)
| 3435 | |
| 3436 | |
| 3437 | def GetLineWidth(line): |
| 3438 | """Determines the width of the line in column positions. |
| 3439 | |
| 3440 | Args: |
| 3441 | line: A string, which may be a Unicode string. |
| 3442 | |
| 3443 | Returns: |
| 3444 | The width of the line in column positions, accounting for Unicode |
| 3445 | combining characters and wide characters. |
| 3446 | """ |
| 3447 | if isinstance(line, unicode): |
| 3448 | width = 0 |
| 3449 | for uc in unicodedata.normalize('NFC', line): |
| 3450 | if unicodedata.east_asian_width(uc) in ('W', 'F'): |
| 3451 | width += 2 |
| 3452 | elif not unicodedata.combining(uc): |
| 3453 | width += 1 |
| 3454 | return width |
| 3455 | else: |
| 3456 | return len(line) |
| 3457 | |
| 3458 | |
| 3459 | def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state, |