MCPcopy Index your code
hub / github.com/RustPython/RustPython / _display_width

Function _display_width

Lib/traceback.py:960–977  ·  view source on GitHub ↗

Calculate the extra amount of width space the given source code segment might take if it were to be displayed on a fixed width output device. Supports wide unicode characters and emojis.

(line, offset=None)

Source from the content-addressed store, hash-verified

958_WIDE_CHAR_SPECIFIERS = "WF"
959
960def _display_width(line, offset=None):
961 """Calculate the extra amount of width space the given source
962 code segment might take if it were to be displayed on a fixed
963 width output device. Supports wide unicode characters and emojis."""
964
965 if offset is None:
966 offset = len(line)
967
968 # Fast track for ASCII-only strings
969 if line.isascii():
970 return offset
971
972 import unicodedata
973
974 return sum(
975 2 if unicodedata.east_asian_width(char) in _WIDE_CHAR_SPECIFIERS else 1
976 for char in line[:offset]
977 )
978
979
980

Callers 2

format_frame_summaryMethod · 0.85
output_lineMethod · 0.85

Calls 4

lenFunction · 0.85
east_asian_widthMethod · 0.80
sumFunction · 0.50
isasciiMethod · 0.45

Tested by

no test coverage detected