MCPcopy Index your code
hub / github.com/python/cpython / str_width

Function str_width

Lib/_pyrepl/utils.py:63–75  ·  view source on GitHub ↗
(c: str)

Source from the content-addressed store, hash-verified

61
62@functools.cache
63def str_width(c: str) -> int:
64 if ord(c) < 128:
65 return 1
66 # gh-139246 for zero-width joiner and combining characters
67 if unicodedata.combining(c):
68 return 0
69 category = unicodedata.category(c)
70 if category == "Cf" and c != "\u00ad":
71 return 0
72 w = unicodedata.east_asian_width(c)
73 if w in ("N", "Na", "H", "A"):
74 return 1
75 return 2
76
77
78def wlen(s: str) -> int:

Callers 3

test_str_widthMethod · 0.90
wlenFunction · 0.85
disp_strFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_str_widthMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…