SearchBox/SearchBox-CLI/Utilities/LineIterator.cs

34 lines
No EOL
677 B
C#

using System;
using System.Collections.Generic;
using System.IO;
namespace SBRL.Utilities
{
static class LineIterator {
public static IEnumerable<string> GetLines(TextReader source)
{
string nextLine;
while ((nextLine = source.ReadLine()) != null) {
yield return nextLine;
}
}
public static IEnumerable<string> GetLines(string source)
{
source = source.Replace("\r\n", "\n");
int curPosition = 0, nextIndex;
while (true)
{
nextIndex = source.IndexOf("\n", curPosition);
if (nextIndex == -1)
break;
yield return source.Substring(curPosition, nextIndex - curPosition);
curPosition = nextIndex + 1;
}
}
}
}