Normalize a table row to have leading/trailing pipes.
(line: str, expected_cols: int = 0)
| 35 | |
| 36 | |
| 37 | def normalize_row(line: str, expected_cols: int = 0) -> str: |
| 38 | """Normalize a table row to have leading/trailing pipes.""" |
| 39 | stripped = line.strip().rstrip(" ") |
| 40 | # Remove existing leading/trailing pipes |
| 41 | if stripped.startswith("|"): |
| 42 | stripped = stripped[1:] |
| 43 | if stripped.endswith("|"): |
| 44 | stripped = stripped[:-1] |
| 45 | cells = [c.strip() for c in stripped.split("|")] |
| 46 | # Pad or trim to expected column count if specified |
| 47 | if expected_cols > 0: |
| 48 | while len(cells) < expected_cols: |
| 49 | cells.append("") |
| 50 | cells = cells[:expected_cols] |
| 51 | return "| " + " | ".join(cells) + " |" |
| 52 | |
| 53 | |
| 54 | def normalize_separator(line: str, expected_cols: int = 0) -> str: |
no outgoing calls
no test coverage detected