@@ 4419-4438 (lines=20) @@ | ||
4416 | _ALT_TOKEN_REPLACEMENT[match.group(1)], match.group(1))) |
|
4417 | ||
4418 | ||
4419 | def GetLineWidth(line): |
|
4420 | """Determines the width of the line in column positions. |
|
4421 | ||
4422 | Args: |
|
4423 | line: A string, which may be a Unicode string. |
|
4424 | ||
4425 | Returns: |
|
4426 | The width of the line in column positions, accounting for Unicode |
|
4427 | combining characters and wide characters. |
|
4428 | """ |
|
4429 | if isinstance(line, unicode): |
|
4430 | width = 0 |
|
4431 | for uc in unicodedata.normalize('NFC', line): |
|
4432 | if unicodedata.east_asian_width(uc) in ('W', 'F'): |
|
4433 | width += 2 |
|
4434 | elif not unicodedata.combining(uc): |
|
4435 | width += 1 |
|
4436 | return width |
|
4437 | else: |
|
4438 | return len(line) |
|
4439 | ||
4440 | ||
4441 | def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state, |
@@ 4419-4438 (lines=20) @@ | ||
4416 | _ALT_TOKEN_REPLACEMENT[match.group(1)], match.group(1))) |
|
4417 | ||
4418 | ||
4419 | def GetLineWidth(line): |
|
4420 | """Determines the width of the line in column positions. |
|
4421 | ||
4422 | Args: |
|
4423 | line: A string, which may be a Unicode string. |
|
4424 | ||
4425 | Returns: |
|
4426 | The width of the line in column positions, accounting for Unicode |
|
4427 | combining characters and wide characters. |
|
4428 | """ |
|
4429 | if isinstance(line, unicode): |
|
4430 | width = 0 |
|
4431 | for uc in unicodedata.normalize('NFC', line): |
|
4432 | if unicodedata.east_asian_width(uc) in ('W', 'F'): |
|
4433 | width += 2 |
|
4434 | elif not unicodedata.combining(uc): |
|
4435 | width += 1 |
|
4436 | return width |
|
4437 | else: |
|
4438 | return len(line) |
|
4439 | ||
4440 | ||
4441 | def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state, |