Implement a generator function that processes a multi-line document string step by step. The document lines are separated by newline characters, and within each line fields are separated by a given separator character. Fields may be surrounded by double quotes; quoted fields can contain the separator character without it being treated as a delimiter.
Your generator should accept two inputs:
represent_doc: a string containing the full document, with lines delimited by newlines.separator: a string that acts as the field delimiter within each line.On each iteration, yield a dictionary that maps stringified field indices to the corresponding field's string value for the current line. Fields must be extracted while respecting the quoting rules described above.
represent_doc (str): The entire document content, with lines separated by \n characters. Some fields may be enclosed in double quotes.separator (str): The character used to separate fields within a line.dict with keys '0', '1', …, 'N-1' and values being the unquoted string content of each field for that line.represent_doc = 'name,age
"squarepoint, is, hiring",25
John,30'
separator = ','
Output:
{'0': 'name', '1': 'age'}
{'0': 'squarepoint, is, hiring', '1': '25'}
{'0': 'John', '1': '30'}
Explanation:
name and age."squarepoint, is, hiring", so the embedded commas are kept inside the value.represent_doc is at most 10^5 characters.