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

Function parse_basic_str

Lib/tomllib/_parser.py:636–665  ·  view source on GitHub ↗
(src: str, pos: Pos, *, multiline: bool)

Source from the content-addressed store, hash-verified

634
635
636def parse_basic_str(src: str, pos: Pos, *, multiline: bool) -> tuple[Pos, str]:
637 if multiline:
638 error_on = ILLEGAL_MULTILINE_BASIC_STR_CHARS
639 parse_escapes = parse_basic_str_escape_multiline
640 else:
641 error_on = ILLEGAL_BASIC_STR_CHARS
642 parse_escapes = parse_basic_str_escape
643 result = ""
644 start_pos = pos
645 while True:
646 try:
647 char = src[pos]
648 except IndexError:
649 raise TOMLDecodeError("Unterminated string", src, pos) from None
650 if char == '"':
651 if not multiline:
652 return pos + 1, result + src[start_pos:pos]
653 if src.startswith('"""', pos):
654 return pos + 3, result + src[start_pos:pos]
655 pos += 1
656 continue
657 if char == "\\":
658 result += src[start_pos:pos]
659 pos, parsed_escape = parse_escapes(src, pos)
660 result += parsed_escape
661 start_pos = pos
662 continue
663 if char in error_on:
664 raise TOMLDecodeError(f"Illegal character {char!r}", src, pos)
665 pos += 1
666
667
668def parse_value(

Callers 2

parse_one_line_basic_strFunction · 0.85
parse_multiline_strFunction · 0.85

Calls 2

TOMLDecodeErrorClass · 0.85
startswithMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…