MCPcopy
hub / github.com/psf/black / count_chars_in_width

Function count_chars_in_width

src/black/strings.py:380–391  ·  view source on GitHub ↗

Count the number of characters in `line_str` that would fit in a terminal or editor of `max_width` (which respects Unicode East Asian Width).

(line_str: str, max_width: int)

Source from the content-addressed store, hash-verified

378
379
380def count_chars_in_width(line_str: str, max_width: int) -> int:
381 """Count the number of characters in `line_str` that would fit in a
382 terminal or editor of `max_width` (which respects Unicode East Asian
383 Width).
384 """
385 total_width = 0
386 for i, char in enumerate(line_str):
387 width = char_width(char)
388 if width + total_width > max_width:
389 return i
390 total_width += width
391 return len(line_str)

Callers 2

do_transformMethod · 0.90

Calls 1

char_widthFunction · 0.85

Tested by

no test coverage detected