Browse Source

Change CSVParser to use Regex.Split (way faster)

master
Christopher 8 years ago
parent
commit
0504eb3651
  1. 21
      Assets/Fungus/Thirdparty/CSVParser/CsvParser.cs

21
Assets/Fungus/Thirdparty/CSVParser/CsvParser.cs vendored

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
namespace Ideafixxxer.CsvParser
{
@ -190,15 +191,22 @@ namespace Ideafixxxer.CsvParser
var context = new ParserContext();
// Handle both Windows and Mac line endings
string[] lines = csvData.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
var lines = Regex.Split(csvData, "\n|\r\n");
ParserState currentState = ParserState.LineStartState;
foreach (string next in lines)
{
foreach (char ch in next)
{
switch (ch)
for (int i = 0; i < lines.Length; i++) {
var next = lines [i];
// Skip empty entries
if (next.Length == 0)
{
continue;
}
for (int j = 0; j < next.Length; j++) {
var ch = next [j];
switch (ch) {
case CommaCharacter:
currentState = currentState.Comma (context);
break;
@ -212,6 +220,7 @@ namespace Ideafixxxer.CsvParser
}
currentState = currentState.EndOfLine (context);
}
List<string[]> allLines = context.GetAllLines();
return allLines.ToArray();
}

Loading…
Cancel
Save