(line: str, line_state: LineState, state: ColumnsState)
| 283 | |
| 284 | |
| 285 | def ProcessLine(line: str, line_state: LineState, state: ColumnsState) -> LineState: |
| 286 | if line_state == LineState.IN_TABLE: |
| 287 | if line.endswith("// clang-format on"): |
| 288 | return LineState.NONE |
| 289 | row = ParseRow(line, state) |
| 290 | if len(row.columns) < 2: |
| 291 | return line_state |
| 292 | if not state.widths: |
| 293 | state.first_row = list(row.columns) |
| 294 | for column in row.columns: |
| 295 | state.widths.append(len(column) + 1) |
| 296 | state.aligns.append(ColumnAlign.RIGHT) |
| 297 | return line_state |
| 298 | if len(row.columns) != len(state.widths): |
| 299 | raise RuntimeError( |
| 300 | f"Expected {len(state.widths)} columns, got {len(row.columns)}.\n" |
| 301 | + CompareRows(state.first_row, row.columns) |
| 302 | ) |
| 303 | for i in range(len(row.columns)): |
| 304 | column = row.columns[i] |
| 305 | state.widths[i] = max(len(column), state.widths[i]) |
| 306 | if column and not _RIGHT_ALIGN_RE.match(column): |
| 307 | state.aligns[i] = ColumnAlign.LEFT |
| 308 | elif line.endswith("// clang-format off"): |
| 309 | return LineState.IN_TABLE |
| 310 | return line_state |
| 311 | |
| 312 | |
| 313 | def FormatColumn(column: str, align: ColumnAlign, width: int): |
no test coverage detected