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

Function PyUnicode_DecodeUnicodeEscape

Lib/_pycodecs.py:1501–1648  ·  view source on GitHub ↗
(s, size, errors, final)

Source from the content-addressed store, hash-verified

1499
1500
1501def PyUnicode_DecodeUnicodeEscape(s, size, errors, final):
1502 if size == 0:
1503 return "", 0
1504
1505 if isinstance(s, str):
1506 s = s.encode()
1507
1508 found_invalid_escape = False
1509
1510 p = []
1511 pos = 0
1512 while pos < size:
1513 ## /* Non-escape characters are interpreted as Unicode ordinals */
1514 if s[pos] != ord("\\"):
1515 p.append(chr(s[pos]))
1516 pos += 1
1517 continue
1518 ## /* \ - Escapes */
1519 escape_start = pos
1520 pos += 1
1521 if pos >= size:
1522 if not final:
1523 pos = escape_start
1524 break
1525 errmessage = "\\ at end of string"
1526 unicode_call_errorhandler(
1527 errors, "unicodeescape", errmessage, s, pos - 1, size
1528 )
1529 break
1530 ch = chr(s[pos])
1531 pos += 1
1532 ## /* \x escapes */
1533 if ch == "\n":
1534 pass
1535 elif ch == "\\":
1536 p += "\\"
1537 elif ch == "'":
1538 p += "'"
1539 elif ch == '"':
1540 p += '"'
1541 elif ch == "b":
1542 p += "\b"
1543 elif ch == "f":
1544 p += "\014" # /* FF */
1545 elif ch == "t":
1546 p += "\t"
1547 elif ch == "n":
1548 p += "\n"
1549 elif ch == "r":
1550 p += "\r"
1551 elif ch == "v":
1552 p += "\013" # break; /* VT */
1553 elif ch == "a":
1554 p += "\007" # break; /* BEL, not classic C */
1555 elif "0" <= ch <= "7":
1556 x = ord(ch) - ord("0")
1557 if pos < size:
1558 ch = chr(s[pos])

Callers 1

unicode_escape_decodeFunction · 0.85

Calls 10

isinstanceFunction · 0.85
ordFunction · 0.85
chrFunction · 0.85
hex_number_endFunction · 0.85
hexescapeFunction · 0.70
encodeMethod · 0.45
appendMethod · 0.45
lookupMethod · 0.45
warnMethod · 0.45

Tested by

no test coverage detected