Move .NET implementation to SaneTsv
This commit is contained in:
parent
4dd3a4878e
commit
211e26d4c7
@ -5,19 +5,19 @@ namespace NathanMcRae;
|
||||
/// <summary>
|
||||
/// Sane Tab-Separated Values
|
||||
/// </summary>
|
||||
public class Stsv
|
||||
public class SaneTsv
|
||||
{
|
||||
// TODO: We need to be able to update all these in tandem somehow
|
||||
public string[] ColumnNames { get; protected set; }
|
||||
public Dictionary<string, List<string>> Columns { get; protected set; }
|
||||
public List<StsvRecord> Records { get; protected set; }
|
||||
public List<SaneTsvRecord> Records { get; protected set; }
|
||||
|
||||
public static Stsv Parse(byte[] inputBuffer)
|
||||
public static SaneTsv Parse(byte[] inputBuffer)
|
||||
{
|
||||
var parsed = new Stsv();
|
||||
var parsed = new SaneTsv();
|
||||
parsed.Columns = new Dictionary<string, List<string>>();
|
||||
parsed.ColumnNames = new string[] { };
|
||||
parsed.Records = new List<StsvRecord>();
|
||||
parsed.Records = new List<SaneTsvRecord>();
|
||||
|
||||
var fieldBytes = new List<byte>();
|
||||
var fields = new List<string>();
|
||||
@ -112,7 +112,7 @@ public class Stsv
|
||||
parsed.Columns[parsed.ColumnNames[j]].Add(fields[j]);
|
||||
}
|
||||
|
||||
parsed.Records.Add(new StsvRecord(parsed, fields.ToArray()));
|
||||
parsed.Records.Add(new SaneTsvRecord(parsed, fields.ToArray()));
|
||||
fields.Clear();
|
||||
}
|
||||
}
|
||||
@ -149,23 +149,23 @@ public class Stsv
|
||||
}
|
||||
}
|
||||
|
||||
parsed.Records.Add(new StsvRecord(parsed, fields.ToArray()));
|
||||
parsed.Records.Add(new SaneTsvRecord(parsed, fields.ToArray()));
|
||||
fields.Clear();
|
||||
}
|
||||
|
||||
return parsed;
|
||||
}
|
||||
|
||||
public StsvRecord this[int i] => Records[i];
|
||||
public SaneTsvRecord this[int i] => Records[i];
|
||||
|
||||
public class StsvRecord
|
||||
public class SaneTsvRecord
|
||||
{
|
||||
public Stsv Parent { get; }
|
||||
public SaneTsv Parent { get; }
|
||||
public string[] Fields { get; }
|
||||
|
||||
public string this[string columnName] => Fields[Array.IndexOf(Parent.ColumnNames, columnName)];
|
||||
|
||||
public StsvRecord(Stsv parent, string[] fields)
|
||||
public SaneTsvRecord(SaneTsv parent, string[] fields)
|
||||
{
|
||||
Parent = parent;
|
||||
Fields = fields;
|
17
SaneTsv/SaneTsv.csproj
Normal file
17
SaneTsv/SaneTsv.csproj
Normal file
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="SaneTsvTest\**" />
|
||||
<EmbeddedResource Remove="SaneTsvTest\**" />
|
||||
<None Remove="SaneTsvTest\**" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.7.34024.191
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stsv", "Stsv.csproj", "{DBC5CE44-361C-4387-B1E2-409C1CAE2B4C}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SaneTsv", "SaneTsv.csproj", "{DBC5CE44-361C-4387-B1E2-409C1CAE2B4C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StsvTest", "..\StsvTest\StsvTest.csproj", "{43B1B09C-19BD-4B45-B41B-7C00DB3F7E9C}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SaneTsvTest", "SaneTsvTest\SaneTsvTest.csproj", "{43B1B09C-19BD-4B45-B41B-7C00DB3F7E9C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
@ -3,6 +3,6 @@ using System.Text;
|
||||
|
||||
string testString1 = "column1\tcolumn2\tcolumnthree\\nyep\nvalue1\tvalue\\\\twoo\tvaluetrhee\nthis\\nis\\na\\nvalue\tnother\tno\\ther";
|
||||
|
||||
Stsv parsed = Stsv.Parse(Encoding.UTF8.GetBytes(testString1));
|
||||
SaneTsv parsed = SaneTsv.Parse(Encoding.UTF8.GetBytes(testString1));
|
||||
// See https://aka.ms/new-console-template for more information
|
||||
Console.WriteLine("Hello, World!");
|
@ -8,7 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Stsv\Stsv.csproj" />
|
||||
<ProjectReference Include="..\SaneTsv.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,9 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user