/// <summary>
/// Finds the next sequence of newlines in the input stream.
/// </summary>
/// <param name="data">The data to search</param>
/// <param name="offset">The offset to start searching at</param>
/// <param name="maxBytes">The maximum number of bytes (starting from offset) to search.</param>
/// <returns>The offset of the next newline</returns>
private int FindNextNewline(ref byte[] data, int offset, int maxBytes)
{
byte[][] newlinePatterns = { this.Encoding.GetBytes("\r\n"), this.Encoding.GetBytes("\n") };
Array.Sort(newlinePatterns, (first, second) => second.Length.CompareTo(first.Length));
byte[] dataRef = data;
if (offset != 0)
{
dataRef = data.Skip(offset).ToArray();
}
foreach (var pattern in newlinePatterns)
{
int position = SubsequenceFinder.Search(dataRef, pattern);
if (position != -1)
{
return(position + offset);
}
}
return(-1);
}