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)
| 4349 | |
| 4350 | |
| 4351 | def GetLineWidth(line): |
| 4352 | """Determines the width of the line in column positions. |
| 4353 | |
| 4354 | Args: |
| 4355 | line: A string, which may be a Unicode string. |
| 4356 | |
| 4357 | Returns: |
| 4358 | The width of the line in column positions, accounting for Unicode |
| 4359 | combining characters and wide characters. |
| 4360 | """ |
| 4361 | if isinstance(line, unicode): |
| 4362 | width = 0 |
| 4363 | for uc in unicodedata.normalize('NFC', line): |
| 4364 | if unicodedata.east_asian_width(uc) in ('W', 'F'): |
| 4365 | width += 2 |
| 4366 | elif not unicodedata.combining(uc): |
| 4367 | width += 1 |
| 4368 | return width |
| 4369 | else: |
| 4370 | return len(line) |
| 4371 | |
| 4372 | |
| 4373 | def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state, |