MCPcopy Create free account
hub / github.com/diasurgical/DevilutionX / ProcessLine

Function ProcessLine

tools/cpp_format_struct_table.py:285–310  ·  view source on GitHub ↗
(line: str, line_state: LineState, state: ColumnsState)

Source from the content-addressed store, hash-verified

283
284
285def 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
313def FormatColumn(column: str, align: ColumnAlign, width: int):

Callers 1

ProcessFunction · 0.85

Calls 2

ParseRowFunction · 0.85
CompareRowsFunction · 0.85

Tested by

no test coverage detected