using System.Text; namespace LehrerApp.WebUntis; internal static class TabSeparatedTextReader { public static List> ParseRows(string content, char separator) { var rows = new List>(); var row = new List(); var field = new StringBuilder(); var inQuotes = false; for (var index = 0; index < content.Length; index++) { var character = content[index]; if (character == '"') { if (inQuotes && index + 1 < content.Length && content[index + 1] == '"') { field.Append('"'); index++; } else { inQuotes = !inQuotes; } continue; } if (!inQuotes && character == separator) { row.Add(field.ToString()); field.Clear(); continue; } if (!inQuotes && character == '\n') { row.Add(field.ToString()); rows.Add(row); row = []; field.Clear(); continue; } if (!inQuotes && character == '\r') continue; field.Append(character); } row.Add(field.ToString()); if (row.Count > 1 || !string.IsNullOrWhiteSpace(row[0])) rows.Add(row); return rows; } }