aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.CSV
diff options
context:
space:
mode:
authorRoy Ben Shabat <roy.mail.net@gmail.com>2025-09-29 05:46:38 +0300
committerRoy Ben Shabat <roy.mail.net@gmail.com>2025-09-29 05:46:38 +0300
commit9c858b7b51be2eb5b2f515912d436224d7e6483c (patch)
tree46f854bfd37026967ef2dfa8f28a70cd8c8f7727 /Software/Visual_Studio/Tango.CSV
parent103bd3c1c825e4ecbb1c714e293a5c9d97a09c8c (diff)
downloadTango-9c858b7b51be2eb5b2f515912d436224d7e6483c.tar.gz
Tango-9c858b7b51be2eb5b2f515912d436224d7e6483c.zip
Process Parameters Visual Representation.
Filter RML by machine type on Research module.
Diffstat (limited to 'Software/Visual_Studio/Tango.CSV')
-rw-r--r--Software/Visual_Studio/Tango.CSV/CsvDynamicReader.cs42
1 files changed, 42 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.CSV/CsvDynamicReader.cs b/Software/Visual_Studio/Tango.CSV/CsvDynamicReader.cs
index 33ba859eb..d43b9ba3d 100644
--- a/Software/Visual_Studio/Tango.CSV/CsvDynamicReader.cs
+++ b/Software/Visual_Studio/Tango.CSV/CsvDynamicReader.cs
@@ -20,6 +20,48 @@ namespace Tango.CSV
public char Delimiter { get; }
+ public static CsvDynamicReader FromString(String csv)
+ {
+ return new CsvDynamicReader(csv);
+ }
+
+ private CsvDynamicReader(string csvContent)
+ {
+ Delimiter = ',';
+ _colIndex = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
+ _rows = new List<Row>();
+
+ using (var sr = new StringReader(csvContent))
+ {
+ // Read to first non-empty line for headers
+ string headerLine;
+ do
+ {
+ headerLine = sr.ReadLine();
+ if (headerLine == null)
+ throw new InvalidDataException("CSV file has no header row.");
+ } while (string.IsNullOrWhiteSpace(headerLine));
+
+ var headers = ParseCsvLine(headerLine, Delimiter);
+ for (int i = 0; i < headers.Count; i++)
+ {
+ var clean = CleanHeader(headers[i]);
+ if (!_colIndex.ContainsKey(clean))
+ _colIndex.Add(clean, i);
+ // If duplicate header name appears, first one wins.
+ }
+
+ // Read all rows
+ string line;
+ while ((line = sr.ReadLine()) != null)
+ {
+ if (line.Length == 0) continue; // skip empty
+ var fields = ParseCsvLine(line, Delimiter).ToArray();
+ _rows.Add(new Row(this, fields));
+ }
+ }
+ }
+
public CsvDynamicReader(string path, char delimiter = ',')
{
if (path == null) throw new ArgumentNullException(nameof(path));