Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Csv/CsvLineSplitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ private static bool IsUnterminatedQuotedValueCore(SpanText value, char quoteChar
return trailingQuoteCount % 2 != 0;
}

public IList<MemoryText> Split(MemoryText line, CsvOptions options)
public IList<MemoryText> Split(MemoryText line, CsvOptions options, int? capacity = null)
{
#if NET8_0_OR_GREATER
var span = line.Span;
#else
var span = line;
#endif

var values = new List<MemoryText>();
var values = capacity.HasValue ? new List<MemoryText>(capacity.Value) : new List<MemoryText>();
var start = 0;
var inQuotes = false;
char quoteChar = '\0';
Expand Down
16 changes: 8 additions & 8 deletions Csv/CsvReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
break;

line = StringHelpers.Concat(line.AsMemory(), options.NewLine, nextLine.AsMemory()).AsString();
record = new ReadLineSpan(headers, headerLookup, index, line, options);

Check warning on line 217 in Csv/CsvReader.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Possible null reference argument for parameter 'headers' in 'ReadLineSpan.ReadLineSpan(ReadOnlyMemory<char>[] headers, Dictionary<string, int> headerLookup, int index, string raw, CsvOptions options)'.

Check warning on line 217 in Csv/CsvReader.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Possible null reference argument for parameter 'headers' in 'ReadLineSpan.ReadLineSpan(ReadOnlyMemory<char>[] headers, Dictionary<string, int> headerLookup, int index, string raw, CsvOptions options)'.
}
}

Expand Down Expand Up @@ -495,7 +495,7 @@
break;

line += options.NewLine + nextLine;
record = new ReadLine(headers, headerLookup, index, line, options);

Check warning on line 498 in Csv/CsvReader.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Possible null reference argument for parameter 'headers' in 'ReadLine.ReadLine(ReadOnlyMemory<char>[] headers, Dictionary<string, int> headerLookup, int index, string raw, CsvOptions options)'.

Check warning on line 498 in Csv/CsvReader.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Possible null reference argument for parameter 'headers' in 'ReadLine.ReadLine(ReadOnlyMemory<char>[] headers, Dictionary<string, int> headerLookup, int index, string raw, CsvOptions options)'.

Check warning on line 498 in Csv/CsvReader.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Possible null reference argument for parameter 'headers' in 'ReadLine.ReadLine(string[] headers, Dictionary<string, int> headerLookup, int index, string raw, CsvOptions options)'.
}
}

Expand Down Expand Up @@ -736,9 +736,9 @@
options.Splitter = CsvLineSplitter.Get(options);
}

private static IList<MemoryText> SplitLine(MemoryText line, CsvOptions options)
private static IList<MemoryText> SplitLine(MemoryText line, CsvOptions options, int? capacity = null)
{
return options.Splitter.Split(line, options);
return options.Splitter.Split(line, options, capacity);
}

private static MemoryText[] Trim(IList<MemoryText> line, CsvOptions options)
Expand Down Expand Up @@ -883,9 +883,9 @@
get
{
#if NET8_0_OR_GREATER
rawSplitLine ??= SplitLine(Raw.AsMemory(), options);
rawSplitLine ??= SplitLine(Raw.AsMemory(), options, headers?.Length);
#else
rawSplitLine ??= SplitLine(Raw, options);
rawSplitLine ??= SplitLine(Raw, options, headers?.Length);
#endif
return rawSplitLine;
}
Expand Down Expand Up @@ -982,7 +982,7 @@
return RawSplitLine.Count > index;
}

internal IList<MemoryText> RawSplitLine => rawSplitLine ??= SplitLine(Raw.AsMemory(), options);
internal IList<MemoryText> RawSplitLine => rawSplitLine ??= SplitLine(Raw.AsMemory(), options, headers?.Length);

public string[] Values => Line.Select(it => it.AsString()).ToArray();
public ReadOnlyMemory<char>[] ValuesMemory => Line;
Expand Down Expand Up @@ -1126,7 +1126,7 @@
return RawSplitLine.Count > index;
}

internal IList<ReadOnlyMemory<char>> RawSplitLine => rawSplitLine ??= SplitLineOptimized(rawMemory, options, memoryOptions);
internal IList<ReadOnlyMemory<char>> RawSplitLine => rawSplitLine ??= SplitLineOptimized(rawMemory, options, memoryOptions, headers?.Length);

public string[] Values => Line.Select(v => v.ToString()).ToArray();
public ReadOnlyMemory<char>[] ValuesMemory => Line;
Expand Down Expand Up @@ -1229,10 +1229,10 @@
public override string ToString() => Raw;
}

private static IList<ReadOnlyMemory<char>> SplitLineOptimized(ReadOnlyMemory<char> line, CsvOptions options, CsvMemoryOptions memoryOptions)
private static IList<ReadOnlyMemory<char>> SplitLineOptimized(ReadOnlyMemory<char> line, CsvOptions options, CsvMemoryOptions memoryOptions, int? capacity = null)
{
var splitter = CsvLineSplitter.Get(options);
return splitter.Split(line, options);
return splitter.Split(line, options, capacity);
}

private static ReadOnlyMemory<char>[] TrimOptimized(IList<ReadOnlyMemory<char>> line, CsvOptions options, CsvMemoryOptions memoryOptions)
Expand Down
Loading