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)
| 4208 | |
| 4209 | |
| 4210 | def GetLineWidth(line): |
| 4211 | """Determines the width of the line in column positions. |
| 4212 | |
| 4213 | Args: |
| 4214 | line: A string, which may be a Unicode string. |
| 4215 | |
| 4216 | Returns: |
| 4217 | The width of the line in column positions, accounting for Unicode |
| 4218 | combining characters and wide characters. |
| 4219 | """ |
| 4220 | if isinstance(line, str): |
| 4221 | width = 0 |
| 4222 | for uc in unicodedata.normalize('NFC', line): |
| 4223 | if unicodedata.east_asian_width(uc) in ('W', 'F'): |
| 4224 | width += 2 |
| 4225 | elif not unicodedata.combining(uc): |
| 4226 | width += 1 |
| 4227 | return width |
| 4228 | else: |
| 4229 | return len(line) |
| 4230 | |
| 4231 | |
| 4232 | def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state, |
no outgoing calls
no test coverage detected