// TODO: refactor to a shared readFully somewhere
// (NGramTokenizer does this too):
/// <summary>
/// commons-io's readFully, but without bugs if offset != 0 </summary>
private static int Read(TextReader input, char[] buffer, int offset, int length)
{
Debug.Assert(length >= 0, "length must not be negative: " + length);
int remaining = length;
while (remaining > 0)
{
int location = length - remaining;
int count = input.Read(buffer, offset + location, remaining);
if (count <= 0) // EOF
{
break;
}
remaining -= count;
}
return length - remaining;
}