Split a row by delimiter, respecting quoted strings. Args: row_str: Row string to split delimiter: Delimiter character Returns: List of field values
(row_str: str, delimiter: str)
| 381 | |
| 382 | |
| 383 | def _split_row(row_str: str, delimiter: str) -> List[str]: |
| 384 | """ |
| 385 | Split a row by delimiter, respecting quoted strings. |
| 386 | |
| 387 | Args: |
| 388 | row_str: Row string to split |
| 389 | delimiter: Delimiter character |
| 390 | |
| 391 | Returns: |
| 392 | List of field values |
| 393 | """ |
| 394 | values = [] |
| 395 | current = [] |
| 396 | in_quote = False |
| 397 | i = 0 |
| 398 | |
| 399 | while i < len(row_str): |
| 400 | char = row_str[i] |
| 401 | |
| 402 | if char == QUOTE: |
| 403 | if in_quote and i + 1 < len(row_str) and row_str[i + 1] == QUOTE: |
| 404 | # Escaped quote |
| 405 | current.append(QUOTE) |
| 406 | i += 2 |
| 407 | else: |
| 408 | in_quote = not in_quote |
| 409 | i += 1 |
| 410 | elif char == delimiter and not in_quote: |
| 411 | values.append(''.join(current)) |
| 412 | current = [] |
| 413 | i += 1 |
| 414 | else: |
| 415 | current.append(char) |
| 416 | i += 1 |
| 417 | |
| 418 | # Add last value |
| 419 | if current or values: |
| 420 | values.append(''.join(current)) |
| 421 | |
| 422 | return values |
| 423 | |
| 424 | |
| 425 | def _parse_value(value_str: str, opts: DecoderOptions) -> Any: |
no outgoing calls
no test coverage detected
searching dependent graphs…