MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / parse_basic_str

Function parse_basic_str

tools/python-3.11.9-amd64/Lib/tomllib/_parser.py:552–581  ·  view source on GitHub ↗
(src: str, pos: Pos, *, multiline: bool)

Source from the content-addressed store, hash-verified

550
551
552def parse_basic_str(src: str, pos: Pos, *, multiline: bool) -> tuple[Pos, str]:
553 if multiline:
554 error_on = ILLEGAL_MULTILINE_BASIC_STR_CHARS
555 parse_escapes = parse_basic_str_escape_multiline
556 else:
557 error_on = ILLEGAL_BASIC_STR_CHARS
558 parse_escapes = parse_basic_str_escape
559 result = ""
560 start_pos = pos
561 while True:
562 try:
563 char = src[pos]
564 except IndexError:
565 raise suffixed_err(src, pos, "Unterminated string") from None
566 if char == '"':
567 if not multiline:
568 return pos + 1, result + src[start_pos:pos]
569 if src.startswith('"""', pos):
570 return pos + 3, result + src[start_pos:pos]
571 pos += 1
572 continue
573 if char == "\\":
574 result += src[start_pos:pos]
575 pos, parsed_escape = parse_escapes(src, pos)
576 result += parsed_escape
577 start_pos = pos
578 continue
579 if char in error_on:
580 raise suffixed_err(src, pos, f"Illegal character {char!r}")
581 pos += 1
582
583
584def parse_value( # noqa: C901

Callers 2

parse_one_line_basic_strFunction · 0.70
parse_multiline_strFunction · 0.70

Calls 2

startswithMethod · 0.80
suffixed_errFunction · 0.70

Tested by

no test coverage detected