Migrate CsvLib to net 7.0
This commit is contained in:
@@ -7,7 +7,7 @@ namespace CsvLib
|
||||
{
|
||||
private readonly TextReader _baseReader;
|
||||
private int _position;
|
||||
private readonly StringBuilder _sbBuffer = new StringBuilder();
|
||||
private readonly StringBuilder _sbBuffer = new();
|
||||
|
||||
private readonly Encoding _currentEncoding = Encoding.Default;
|
||||
|
||||
|
||||
@@ -22,11 +22,11 @@ namespace CsvLib
|
||||
_escapeChar = escapeChar;
|
||||
}
|
||||
|
||||
private List<long> _index = new List<long>();
|
||||
private List<long> _index = new();
|
||||
|
||||
public List<long> Index { get { return _index; } }
|
||||
|
||||
private List<List<long>> _fieldIndex = new List<List<long>>();
|
||||
private List<List<long>> _fieldIndex = new();
|
||||
|
||||
public List<List<long>> FieldIndex { get { return _fieldIndex; } }
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace CsvLib
|
||||
|
||||
private List<long> ParseLineIndex(string line, long lineOffset)
|
||||
{
|
||||
List<long> fieldPositions = new List<long>();
|
||||
List<long> fieldPositions = new();
|
||||
long? fieldStartPosition = null;
|
||||
long? fieldEndPosition = null;
|
||||
int unicodeDelta = 0;
|
||||
@@ -99,7 +99,7 @@ namespace CsvLib
|
||||
}
|
||||
|
||||
long absolutePosition = lineOffset + i + unicodeDelta;
|
||||
if (fieldStartPosition == null) { fieldStartPosition = absolutePosition; }
|
||||
fieldStartPosition ??= absolutePosition;
|
||||
fieldEndPosition = absolutePosition;
|
||||
}
|
||||
}
|
||||
@@ -116,11 +116,9 @@ namespace CsvLib
|
||||
|
||||
public void GenerateIndex(string file)
|
||||
{
|
||||
using (FileStream stream = new FileStream(file, FileMode.Open))
|
||||
using (StreamReader streamReader = new StreamReader(stream, Encoding.Default, true, 4096))
|
||||
{
|
||||
GenerateIndex(streamReader);
|
||||
}
|
||||
using FileStream stream = new(file, FileMode.Open);
|
||||
using StreamReader streamReader = new(stream, Encoding.Default, true, 4096);
|
||||
GenerateIndex(streamReader);
|
||||
}
|
||||
|
||||
public void GenerateIndex(TextReader textReader)
|
||||
@@ -133,50 +131,53 @@ namespace CsvLib
|
||||
{
|
||||
_currentEncoding = streamReader.CurrentEncoding;
|
||||
}
|
||||
using (BufferedTextReader reader = new BufferedTextReader(textReader))
|
||||
using BufferedTextReader reader = new(textReader);
|
||||
string currentLine;
|
||||
while ((currentLine = reader.ReadLine()) != null)
|
||||
{
|
||||
string currentLine;
|
||||
while ((currentLine = reader.ReadLine()) != null)
|
||||
{
|
||||
DummyParser(currentLine);
|
||||
if (_insideString) { continue; }
|
||||
DummyParser(currentLine);
|
||||
if (_insideString) { continue; }
|
||||
|
||||
string fullLine = reader.GetBuffer();
|
||||
reader.CleanBuffer();
|
||||
List<long> fieldIndexes = ParseLineIndex(fullLine, _index[idxRow]);
|
||||
_fieldIndex.Add(fieldIndexes);
|
||||
string fullLine = reader.GetBuffer();
|
||||
reader.CleanBuffer();
|
||||
List<long> fieldIndexes = ParseLineIndex(fullLine, _index[idxRow]);
|
||||
_fieldIndex.Add(fieldIndexes);
|
||||
|
||||
_index.Add(reader.Position);
|
||||
_index.Add(reader.Position);
|
||||
|
||||
idxRow++;
|
||||
}
|
||||
idxRow++;
|
||||
}
|
||||
}
|
||||
|
||||
private void Index_SaveFile(string indexFile)
|
||||
{
|
||||
if (indexFile == null) { return; }
|
||||
if (File.Exists(indexFile))
|
||||
{
|
||||
File.Delete(indexFile);
|
||||
}
|
||||
Stream streamOut = File.Open(indexFile, FileMode.Create);
|
||||
using (BinaryWriter binWriter = new BinaryWriter(streamOut))
|
||||
using (BinaryWriter binWriter = new(streamOut))
|
||||
{
|
||||
binWriter.Write(_index.Count);
|
||||
for (int i = 0; i < _index.Count; i++)
|
||||
{
|
||||
binWriter.Write(_index[i]);
|
||||
}
|
||||
binWriter.Write("test");
|
||||
}
|
||||
streamOut.Close();
|
||||
}
|
||||
|
||||
private static List<long> Index_LoadFile(string indexFile)
|
||||
private void Index_LoadFile(string indexFile)
|
||||
{
|
||||
List<long> tempIndex = new List<long>();
|
||||
|
||||
if (File.Exists(indexFile) == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
List<long> tempIndex = new();
|
||||
Stream streamIn = File.Open(indexFile, FileMode.Open);
|
||||
using (BinaryReader binReader = new BinaryReader(streamIn))
|
||||
using (BinaryReader binReader = new(streamIn))
|
||||
{
|
||||
int numRegs = binReader.ReadInt32();
|
||||
for (int i = 0; i < numRegs; i++)
|
||||
@@ -186,7 +187,7 @@ namespace CsvLib
|
||||
}
|
||||
}
|
||||
streamIn.Close();
|
||||
return tempIndex;
|
||||
_index = tempIndex;
|
||||
}
|
||||
|
||||
public void LoadIndexOfFile(string file)
|
||||
@@ -195,7 +196,7 @@ namespace CsvLib
|
||||
string indexFile = $"{file}.idx2";
|
||||
if (File.Exists(indexFile) && File.GetCreationTime(indexFile) > dtFile)
|
||||
{
|
||||
_index = Index_LoadFile(indexFile);
|
||||
Index_LoadFile(indexFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace CsvLib
|
||||
_escapeChar = escapeChar;
|
||||
}
|
||||
|
||||
private List<long> _index = new List<long>();
|
||||
private List<long> _index = new();
|
||||
|
||||
public List<long> Index { get { return _index; } }
|
||||
|
||||
@@ -54,34 +54,31 @@ namespace CsvLib
|
||||
{
|
||||
_insideString = false;
|
||||
_index.Clear();
|
||||
using (FileStream stream = new FileStream(file, FileMode.Open))
|
||||
using (StreamReader streamReader = new StreamReader(stream, Encoding.Default, true, 4096))
|
||||
using (TrackingTextReader reader = new TrackingTextReader(streamReader))
|
||||
_index.Add(0);
|
||||
using FileStream stream = new(file, FileMode.Open);
|
||||
using StreamReader streamReader = new(stream, Encoding.Default, true, 4096);
|
||||
using TrackingTextReader reader = new(streamReader);
|
||||
|
||||
string currentLine;
|
||||
while ((currentLine = reader.ReadLine()) != null)
|
||||
{
|
||||
string currentLine;
|
||||
DummyParser(currentLine);
|
||||
if (_insideString == false)
|
||||
{
|
||||
_index.Add(reader.Position);
|
||||
}
|
||||
while ((currentLine = reader.ReadLine()) != null)
|
||||
{
|
||||
DummyParser(currentLine);
|
||||
if (_insideString == false)
|
||||
{
|
||||
_index.Add(reader.Position);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Index_SaveFile(string indexFile)
|
||||
{
|
||||
if (indexFile == null) { return; }
|
||||
if (File.Exists(indexFile))
|
||||
{
|
||||
File.Delete(indexFile);
|
||||
}
|
||||
Stream streamOut = File.Open(indexFile, FileMode.Create);
|
||||
using (BinaryWriter binWriter = new BinaryWriter(streamOut))
|
||||
using (BinaryWriter binWriter = new(streamOut))
|
||||
{
|
||||
binWriter.Write(_index.Count);
|
||||
for (int i = 0; i < _index.Count; i++)
|
||||
@@ -94,10 +91,10 @@ namespace CsvLib
|
||||
|
||||
private static List<long> Index_LoadFile(string indexFile)
|
||||
{
|
||||
List<long> tempIndex = new List<long>();
|
||||
List<long> tempIndex = new();
|
||||
|
||||
Stream streamIn = File.Open(indexFile, FileMode.Open);
|
||||
using (BinaryReader binReader = new BinaryReader(streamIn))
|
||||
using (BinaryReader binReader = new(streamIn))
|
||||
{
|
||||
int numRegs = binReader.ReadInt32();
|
||||
for (int i = 0; i < numRegs; i++)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<LangVersion>11</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace CsvLib
|
||||
_escapeChar = escapeChar;
|
||||
}
|
||||
|
||||
private List<List<string>> _data = new List<List<string>>();
|
||||
private List<List<string>> _data = new();
|
||||
|
||||
private List<string> _currentReg;
|
||||
StringBuilder _currentCell;
|
||||
@@ -29,16 +29,10 @@ namespace CsvLib
|
||||
get { return _data; }
|
||||
}
|
||||
|
||||
public void ParseLine(string line)
|
||||
private void ParseLine(string line)
|
||||
{
|
||||
if (_currentReg == null)
|
||||
{
|
||||
_currentReg = new List<string>();
|
||||
}
|
||||
if (_currentCell == null)
|
||||
{
|
||||
_currentCell = new StringBuilder();
|
||||
}
|
||||
_currentReg ??= new List<string>();
|
||||
_currentCell ??= new StringBuilder();
|
||||
|
||||
for (int i = 0; i < line.Length; i++)
|
||||
{
|
||||
@@ -88,9 +82,9 @@ namespace CsvLib
|
||||
_insideString = false;
|
||||
_data = new List<List<string>>();
|
||||
_currentReg = null;
|
||||
FileStream stream = new FileStream(file, FileMode.Open);
|
||||
FileStream stream = new(file, FileMode.Open);
|
||||
stream.Seek(offset, SeekOrigin.Begin);
|
||||
using (StreamReader reader = new StreamReader(stream, Encoding.Default, true, 4096))
|
||||
using (StreamReader reader = new(stream, Encoding.Default, true, 4096))
|
||||
{
|
||||
string currentLine;
|
||||
while ((currentLine = reader.ReadLine()) != null)
|
||||
|
||||
Reference in New Issue
Block a user