public bool ActOnCells(TextAsset textAsset, CellVisitor cellVisitor, out TextAssetTableResult tableResult) { tableResult = new TextAssetTableResult(); var i = 0; foreach (var row in SplitTableToRows(textAsset)) { tableResult.Rows++; var colCount = 0; var j = 0; foreach (var col in SplitRowToCells(row)) { colCount++; if (cellVisitor(i, j, col)) { tableResult.CellsActedOn++; } j++; } tableResult.Cols = Math.Max(tableResult.Cols, colCount); i++; } return(tableResult.CellsActedOn > 0); }
public void ActOnCells(TextAsset textAsset, Action <string> cellAction, out TextAssetTableResult tableResult) { ActOnCells(textAsset, cell => { cellAction(cell); return(false); }, out tableResult); }
public bool ActOnCells(TextAsset textAsset, Func <string, bool> cellVisitor, out TextAssetTableResult tableResult) { bool CellVisitorWrapper(int i, int j, string cellContents) { var _ = (i == j); return(cellVisitor(cellContents)); } return(ActOnCells(textAsset, CellVisitorWrapper, out tableResult)); }
public string ProcessTable(TextAsset textAsset, CellTransform columnTransform, out TextAssetTableResult tableResult) { tableResult = new TextAssetTableResult(); var colJoin = ColSplitStrings.First(); var result = new StringBuilder(textAsset.text.Length * 2); var colBuilder = new StringBuilder(); bool ColumnTransformWrapper(int rowIndex, int colIndex, string col, out string newCol) { if (!columnTransform(rowIndex, colIndex, col, out newCol)) { return(false); } colBuilder.Length = 0; colBuilder.Append(newCol); colBuilder = InvalidColStrings.Aggregate(colBuilder, (current, invalid) => current.Replace(invalid, " ")); newCol = colBuilder.ToString(); return(true); } var table = SplitTable(textAsset); tableResult.Rows = table.Length; tableResult.Cols = 0; for (var r = 0; r < table.Length; r++) { var rowUpdated = false; tableResult.Cols = Math.Max(tableResult.Cols, table[r].Length); for (var c = 0; c < table[r].Length; c++) { var col = table[r][c]; tableResult.Cols = Math.Max(tableResult.Cols, col.Length); if (ColumnTransformWrapper(r, c, col, out var newCol)) { tableResult.CellsUpdated++; rowUpdated = true; result.Append(newCol); } else { result.Append(col); } result.Append(colJoin); } // row complete // remove trailing colSplit result.Length -= colJoin.Length; result.Append(Environment.NewLine); if (rowUpdated) { tableResult.RowsUpdated++; } } // table complete // remove last newline result.Length -= Environment.NewLine.Length; return(tableResult.Updated ? result.ToString() : textAsset.text); }