public char[] Get(int posStart, int length)
{
Debug.Assert(length > 0);
Debug.Assert(InBounds(posStart), "posStart=" + posStart + " length=" + length);
//System.out.println(" buffer.Get posStart=" + posStart + " len=" + length);
int startIndex = GetIndex(posStart);
int endIndex = GetIndex(posStart + length);
//System.out.println(" startIndex=" + startIndex + " endIndex=" + endIndex);
var result = new char[length];
if (endIndex >= startIndex && length < buffer.Length)
{
Array.Copy(buffer, startIndex, result, 0, endIndex - startIndex);
}
else
{
// Wrapped:
int part1 = buffer.Length - startIndex;
Array.Copy(buffer, startIndex, result, 0, part1);
Array.Copy(buffer, 0, result, buffer.Length - startIndex, length - part1);
}
return result;
}