static private AbsolutizeRange ( int &offset, int &length, int count ) : void | ||
offset | int | /// The offset of the range relative to the beginning (if non-negative) or the end of the array (if negative). /// If the offset underflows or overflows the length is shortened appropriately. /// |
length | int |
/// The length of the range if non-negative. Otherwise, its absolute value is the number of items
/// which will not be included in the range from the end of the array. In the latter case
/// the range ends with the | |
count | int | The number of items in array. Should be non-negative. |
Результат | void |
internal static void AbsolutizeRange(ref int offset, ref int length, int count)
{
Debug.Assert(count >= 0);
// prevents overflows:
if (offset >= count || count == 0)
{
offset = count;
length = 0;
return;
}
// negative offset => offset is relative to the end of the string:
if (offset < 0)
{
offset += count;
if (offset < 0) offset = 0;
}
Debug.Assert(offset >= 0 && offset < count);
if (length < 0)
{
// there is count-offset items from offset to the end of array,
// the last |length| items is taken away:
length = count - offset + length;
if (length < 0) length = 0;
}
else if ((long)offset + length > count)
{
// interval ends on the end of array:
length = count - offset;
}
Debug.Assert(length >= 0 && offset + length <= count);
}