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)
| 2768 | |
| 2769 | |
| 2770 | def GetLineWidth(line): |
| 2771 | """Determines the width of the line in column positions. |
| 2772 | |
| 2773 | Args: |
| 2774 | line: A string, which may be a Unicode string. |
| 2775 | |
| 2776 | Returns: |
| 2777 | The width of the line in column positions, accounting for Unicode |
| 2778 | combining characters and wide characters. |
| 2779 | """ |
| 2780 | if isinstance(line, unicode): |
| 2781 | width = 0 |
| 2782 | for uc in unicodedata.normalize('NFC', line): |
| 2783 | if unicodedata.east_asian_width(uc) in ('W', 'F'): |
| 2784 | width += 2 |
| 2785 | elif not unicodedata.combining(uc): |
| 2786 | width += 1 |
| 2787 | return width |
| 2788 | else: |
| 2789 | return len(line) |
| 2790 | |
| 2791 | |
| 2792 | def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state, |