Skip to content

Commit

Permalink
Add SepReaderHeader.TryIndexOf
Browse files Browse the repository at this point in the history
  • Loading branch information
nietras committed Jul 11, 2024
1 parent 0abb208 commit f0702b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Sep.Test/SepReaderHeaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ public void SepReaderHeaderTest_NotEmpty()
AreEqual([0, 2], header.IndicesOf((ReadOnlySpan<string>)["A", "C"]));
AreEqual([2, 0], header.IndicesOf((IReadOnlyList<string>)["C", "A"]));

var tryTrue = header.TryIndexOf("B", out var tryTrueIndex);
Assert.IsTrue(tryTrue);
Assert.AreEqual(1, tryTrueIndex);
var tryFalse = header.TryIndexOf("XX", out var tryFalseIndex);
Assert.IsFalse(tryFalse);
Assert.AreEqual(0, tryFalseIndex);

var actualIndices = new int[2];
header.IndicesOf((ReadOnlySpan<string>)["A", "C"], actualIndices);
AreEqual([0, 2], actualIndices);
Expand Down
2 changes: 2 additions & 0 deletions src/Sep/SepReaderHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ internal static SepReaderHeader Parse(Sep sep, string line, IEqualityComparer<st

public int IndexOf(string colName) => _colNameToIndex[colName];

public bool TryIndexOf(string colName, out int colIndex) => _colNameToIndex.TryGetValue(colName, out colIndex);

public IReadOnlyList<string> NamesStartingWith(string prefix, StringComparison comparison = StringComparison.Ordinal)
{
var colNames = new List<string>();
Expand Down

0 comments on commit f0702b9

Please sign in to comment.