private void GetFieldRange(string row, int currentPos, out int start, out int end)
{
if (string.IsNullOrEmpty(row))
{
start = end = 0;
return;
}
int rowSize = row.Length;
switch (this.Seeker)
{
case FixedWidthPositions.FROM_START:
if (Start < 0)
throw new ArgumentOutOfRangeException("Start", Start, "Seeker is FROM_START, but Start < 0");
start = Start;
if (start >= rowSize)
throw new ArgumentOutOfRangeException("Start", Start, "Seeker is FROM_START, but value of Start results in out of range index");
break;
case FixedWidthPositions.FROM_END:
if (Start < 1)
throw new ArgumentOutOfRangeException("Start", Start, "Seeker is FROM_END, but Start < 1");
start = rowSize - Start;
if (start >= rowSize)
throw new ArgumentOutOfRangeException("Start", Start, "Seeker is FROM_END, but value of Start results in out of range index");
break;
case FixedWidthPositions.FROM_CURRENT:
start = currentPos + Start;
if (start < 0 || start >= rowSize)
throw new ArgumentOutOfRangeException("Start", Start, "Seeker is FROM_CURRENT, but value of current position and Start results in out of range index");
break;
default:
throw new NotImplementedException("Invalid Seeker value");
}
switch (this.Terminator)
{
case FixedWidthTerminators.NEWLINE:
end = rowSize;
break;
case FixedWidthTerminators.LENGTH:
if (End < 0)
throw new ArgumentOutOfRangeException("End", End, "Terminator is LENGTH, but End < 0");
end = start + End;
if (end > rowSize)
throw new ArgumentOutOfRangeException("End", End, "Terminator is LENGTH, but value of current position results in out of range index");
break;
case FixedWidthTerminators.INDEX:
if (End < 0 || End > rowSize)
throw new ArgumentOutOfRangeException("End", End, "Terminator is INDEX, but End is out of range");
else if (End < start)
throw new ArgumentOutOfRangeException("End", End, "Terminator is INDEX, but End < Start");
else
end = End;
break;
default:
throw new NotImplementedException("Invalid Terminator Value");
}
}