public static Task Edit(string path, ForLine edit) { if (File.Exists(path)) { return(Edit(new FileEditor(path), edit)); } return(null); }
public static Task Edit(IEditor editor, ForLine edit) { Task res = new Task(() => { List <string> line = new List <string>(); int nb = 0; while (editor.HasNext()) { Write(editor, edit(JObject.Parse(editor.ReadLine()), nb++)); } editor.Close(); }); res.Start(); return(res); }
public void CSVEditorTest() { EditorTest et = new EditorTest( "A,B,C,D" + "\r\n" + "E,,F,G" + "\r\n" + "H,,I,J" + "\r\n" + "K,,L,\"M,N\"" + "\r\n" + "\r\n" ); ForLine fl = (Line, nb) => new string[] { Line["A"], Line["D"], Line["B"], "C" }; Edit(et, fl).Wait(); AssertThat.AreEqual(et.Out, IS.a( "A,D,B,C" + "\r\n" + "E,G,,C" + "\r\n" + "H,J,,C" + "\r\n" + "K,\"M,N\",,C" + "\r\n" )); }
public static Task Edit(IEditor editor, ForLine edit) { Task res = new Task(() => { string[] ColumnTitle = null; Dictionary <string, string> LineData = null; List <string> line = new List <string>(); int nb = 0; while (editor.HasNext()) { line.Clear(); { int i = 0; line.Add(""); bool guimet = false; bool cont = true; while (cont && editor.HasNext()) { char c = editor.Read(); if (c == '"') { line[i] += c; guimet = !guimet; } else if (guimet) { line[i] += c; } else if (c == ',') { line.Add(""); ++i; } else if (c == '\n') { cont = false; line[i] = line[i][0..^ 1];