本文整理汇总了C#中ParserContext.GetAllLines方法的典型用法代码示例。如果您正苦于以下问题:C# ParserContext.GetAllLines方法的具体用法?C# ParserContext.GetAllLines怎么用?C# ParserContext.GetAllLines使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParserContext
的用法示例。
在下文中一共展示了ParserContext.GetAllLines方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public string[][] Parse(string csvData)
{
var context = new ParserContext();
string[] lines = csvData.Split('\n');
ParserState currentState = ParserState.LineStartState;
foreach (string next in lines)
{
foreach (char ch in next)
{
switch (ch)
{
case CommaCharacter:
currentState = currentState.Comma(context);
break;
case QuoteCharacter:
currentState = currentState.Quote(context);
break;
default:
currentState = currentState.AnyChar(ch, context);
break;
}
}
currentState = currentState.EndOfLine(context);
}
List<string[]> allLines = context.GetAllLines();
return allLines.ToArray();
}
示例2: Parse
public string[][] Parse(TextReader reader)
{
var context = new ParserContext();
ParserState currentState = ParserState.LineStartState;
string next;
while ((next = reader.ReadLine()) != null)
{
foreach (char ch in next)
{
switch (ch)
{
case CommaCharacter:
currentState = currentState.Comma(context);
break;
case QuoteCharacter:
currentState = currentState.Quote(context);
break;
default:
currentState = currentState.AnyChar(ch, context);
break;
}
}
currentState = currentState.EndOfLine(context);
}
List<string[]> allLines = context.GetAllLines();
return allLines.ToArray();
}
示例3: Parse
public string[][] Parse(TextReader reader)
{
var context = new ParserContext();
if (MaxColumnsToRead != 0)
context.MaxColumnsToRead = MaxColumnsToRead;
ParserState currentState = ParserState.LineStartState;
string next;
while ((next = reader.ReadLine()) != null)
{
foreach (char ch in next)
{
switch (ch)
{
case CommaCharacter:
currentState = currentState.Comma(context);
break;
case QuoteCharacter:
currentState = currentState.Quote(context);
break;
default:
currentState = currentState.AnyChar(ch, context);
break;
}
}
currentState = currentState.EndOfLine(context);
}
List<string[]> allLines = context.GetAllLines();
if (TrimTrailingEmptyLines && allLines.Count > 0)
{
bool isEmpty = true;
for (int i = allLines.Count - 1; i >= 0; i--)
{
// ReSharper disable RedundantAssignment
isEmpty = true;
// ReSharper restore RedundantAssignment
for (int j = 0; j < allLines[i].Length; j++)
{
if (!String.IsNullOrEmpty(allLines[i][j]))
{
isEmpty = false;
break;
}
}
if (!isEmpty)
{
if (i < allLines.Count - 1)
allLines.RemoveRange(i + 1, allLines.Count - i - 1);
break;
}
}
if (isEmpty)
allLines.RemoveRange(0, allLines.Count);
}
return allLines.ToArray();
}
示例4: Parse
public string[][] Parse(string csvData)
{
var context = new ParserContext();
// Handle both Windows and Mac line endings
var lines = Regex.Split(csvData, "\n|\r\n");
ParserState currentState = ParserState.LineStartState;
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;
case QuoteCharacter:
currentState = currentState.Quote (context);
break;
default:
currentState = currentState.AnyChar (ch, context);
break;
}
}
currentState = currentState.EndOfLine (context);
}
List<string[]> allLines = context.GetAllLines();
return allLines.ToArray();
}
示例5: Parse
public string[][] Parse(string csvData)
{
var context = new ParserContext();
// Handle both Windows and Mac line endings
string[] lines = csvData.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
ParserState currentState = ParserState.LineStartState;
foreach (string next in lines)
{
foreach (char ch in next)
{
switch (ch)
{
case CommaCharacter:
currentState = currentState.Comma(context);
break;
case QuoteCharacter:
currentState = currentState.Quote(context);
break;
default:
currentState = currentState.AnyChar(ch, context);
break;
}
}
currentState = currentState.EndOfLine(context);
}
List<string[]> allLines = context.GetAllLines();
return allLines.ToArray();
}