-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
74 changed files
with
2,595 additions
and
1,267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#if !NET6_0_OR_GREATER | ||
namespace System.Numerics; | ||
|
||
internal static class BitOperations | ||
{ | ||
public static int TrailingZeroCount(int value) | ||
{ | ||
if (value == 0) | ||
{ | ||
return 32; | ||
} | ||
|
||
var result = 0; | ||
while ((value & 1) == 0) | ||
{ | ||
value >>= 1; | ||
result++; | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#if !NET6_0_OR_GREATER | ||
namespace System.Runtime.CompilerServices; | ||
|
||
internal static class IsExternalInit { } | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#if !NET48_OR_GREATER | ||
namespace System.Linq; | ||
|
||
internal static class ListExtensions | ||
{ | ||
public static List<T> Append<T>(this List<T> list, T item) | ||
{ | ||
list.Add(item); | ||
return list; | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#if !NET6_0_OR_GREATER && !NETSTANDARD2_1_OR_GREATER | ||
using System.Buffers; | ||
|
||
namespace System.IO; | ||
|
||
internal static class TextReaderExtensions | ||
{ | ||
public static int ReadBlock(this TextReader textReader, Span<char> buffer) | ||
{ | ||
char[] array = ArrayPool<char>.Shared.Rent(buffer.Length); | ||
|
||
try | ||
{ | ||
int numRead = textReader.ReadBlock(array, 0, buffer.Length); | ||
if ((uint)numRead > (uint)buffer.Length) | ||
{ | ||
throw new IOException("Invalid read length."); | ||
} | ||
new Span<char>(array, 0, numRead).CopyTo(buffer); | ||
return numRead; | ||
} | ||
finally | ||
{ | ||
ArrayPool<char>.Shared.Return(array); | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#if !NET6_0_OR_GREATER && !NETSTANDARD2_1_OR_GREATER | ||
using System.Buffers; | ||
|
||
namespace System.IO; | ||
|
||
internal static class TextWriterExtensions | ||
{ | ||
public static void Write(this TextWriter textWriter, ReadOnlySpan<char> buffer) | ||
{ | ||
char[] array = ArrayPool<char>.Shared.Rent(buffer.Length); | ||
|
||
try | ||
{ | ||
buffer.CopyTo(new Span<char>(array)); | ||
textWriter.Write(array, 0, buffer.Length); | ||
} | ||
finally | ||
{ | ||
ArrayPool<char>.Shared.Return(array); | ||
} | ||
} | ||
} | ||
#endif |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
namespace CsvHelper.Configuration; | ||
|
||
public abstract record CsvOptions | ||
{ | ||
public char Delimiter { get; init; } = ','; | ||
|
||
public char Escape { get; init; } = '\"'; | ||
|
||
public char? NewLine { get; init; } | ||
|
||
internal int BufferSize = 0x1000; | ||
|
||
internal void Validate() | ||
{ | ||
if (Delimiter == Escape) | ||
{ | ||
throw new ConfigurationException($"{nameof(Delimiter)} and {nameof(Escape)} cannot be the same."); | ||
} | ||
|
||
if (Delimiter == NewLine) | ||
{ | ||
throw new ConfigurationException($"{nameof(Delimiter)} and {nameof(NewLine)} cannot be the same."); | ||
} | ||
|
||
if (Escape == NewLine) | ||
{ | ||
throw new ConfigurationException($"{nameof(Escape)} and {nameof(NewLine)} cannot be the same."); | ||
} | ||
|
||
if (Delimiter < 1) | ||
{ | ||
throw new ConfigurationException($"{nameof(Delimiter)} must be greater than 0."); | ||
} | ||
|
||
if (Escape < 1) | ||
{ | ||
throw new ConfigurationException($"{nameof(Escape)} must be greater than 0."); | ||
} | ||
|
||
if (NewLine < 1) | ||
{ | ||
throw new ConfigurationException($"{nameof(NewLine)} must be greater than 0."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
namespace CsvHelper.Configuration; | ||
|
||
public record CsvParserOptions : CsvOptions | ||
{ | ||
public CsvMode Mode { get; init; } | ||
|
||
public bool CacheFields { get; init; } | ||
|
||
public ParsingStrategy? ParsingStrategy { get; init; } | ||
|
||
internal StringCreator StringCreator = (chars, i) | ||
#if NET6_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER | ||
=> new string(chars); | ||
#else | ||
=> chars.ToString(); | ||
#endif | ||
|
||
internal int ParsedRowsSize = 8; | ||
|
||
internal int ParsedFieldsSize = 8 * 32; | ||
|
||
internal CsvModeParse ModeParse = ModeRfc4180.Parse; | ||
|
||
internal ICsvParsingStrategy ParsingStrategyImplementation = new ThrowParsingStrategy(); | ||
|
||
internal char[] ValidSpecialCharsForIntrinsics = Enumerable | ||
.Range(32, 127 - 32) | ||
.Select(i => (char)i) | ||
.ToList() | ||
.Append('\t') | ||
.Append('\r') | ||
.Append('\n') | ||
.ToArray(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace CsvHelper.Configuration; | ||
|
||
public delegate bool ShouldEscape(ReadOnlySpan<char> field); | ||
|
||
public record CsvSerializerOptions : CsvOptions | ||
{ | ||
public CsvMode Mode { get; init; } | ||
|
||
public ShouldEscape? ShouldEscape { get; init; } | ||
|
||
internal CsvModeEscape ModeEscape = ModeRfc4180.Escape; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace CsvHelper.Configuration; | ||
|
||
public enum ParsingStrategy | ||
{ | ||
IndexOfAny = 0, | ||
#if NET7_0_OR_GREATER | ||
Vector256 = 1, | ||
#endif | ||
#if NET6_0_OR_GREATER | ||
Avx2 = 2, | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace CsvHelper.Configuration; | ||
|
||
public delegate string StringCreator(ReadOnlySpan<char> chars, int columnIndex); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Diagnostics; | ||
|
||
namespace CsvHelper; | ||
|
||
[DebuggerDisplay("Start = {Start}, Length = {Length}, EscapeMask = {EscapeMask}")] | ||
internal record struct CsvField | ||
( | ||
int Start, | ||
int Length, | ||
int EscapeMask, | ||
char[] EscapeBuffer, | ||
int EscapeLength, | ||
bool IsInvalid | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.