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

Function disp_str

Lib/_pyrepl/reader.py:42–69  ·  view source on GitHub ↗

disp_str(buffer:string) -> (string, [int]) Return the string that should be the printed representation of |buffer| and a list detailing where the characters of |buffer| get used up. E.g.: >>> disp_str(chr(3)) ('^C', [1, 0])

(buffer: str)

Source from the content-addressed store, hash-verified

40
41
42def disp_str(buffer: str) -> tuple[str, list[int]]:
43 """disp_str(buffer:string) -> (string, [int])
44
45 Return the string that should be the printed representation of
46 |buffer| and a list detailing where the characters of |buffer|
47 get used up. E.g.:
48
49 >>> disp_str(chr(3))
50 ('^C', [1, 0])
51
52 """
53 b: list[int] = []
54 s: list[str] = []
55 for c in buffer:
56 if c == '\x1a':
57 s.append(c)
58 b.append(2)
59 elif ord(c) < 128:
60 s.append(c)
61 b.append(1)
62 elif unicodedata.category(c).startswith("C"):
63 c = r"\u%04x" % ord(c)
64 s.append(c)
65 b.extend([0] * (len(c) - 1))
66 else:
67 s.append(c)
68 b.append(str_width(c))
69 return "".join(s), b
70
71
72# syntax classes:

Callers 1

calc_screenMethod · 0.85

Calls 8

ordFunction · 0.85
lenFunction · 0.85
str_widthFunction · 0.85
categoryMethod · 0.80
appendMethod · 0.45
startswithMethod · 0.45
extendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected