private StringBuilder(string value, int startIndex, int length, int capacity, int maxCapacity)
{
// first, check the parameters and throw appropriate exceptions if needed
if (null == value)
value = "";
// make sure startIndex is zero or positive
if (startIndex < 0)
throw new System.ArgumentOutOfRangeException ("startIndex", startIndex, "StartIndex cannot be less than zero.");
// make sure length is zero or positive
if(length < 0)
throw new System.ArgumentOutOfRangeException ("length", length, "Length cannot be less than zero.");
if (capacity < 0)
throw new System.ArgumentOutOfRangeException ("capacity", capacity, "capacity must be greater than zero.");
if (maxCapacity < 1)
throw new System.ArgumentOutOfRangeException ("maxCapacity", "maxCapacity is less than one.");
if (capacity > maxCapacity)
throw new System.ArgumentOutOfRangeException ("capacity", "Capacity exceeds maximum capacity.");
// make sure startIndex and length give a valid substring of value
// re-ordered to avoid possible integer overflow
if (startIndex > value.Length - length)
throw new System.ArgumentOutOfRangeException ("startIndex", startIndex, "StartIndex and length must refer to a location within the string.");
if (capacity == 0) {
if (maxCapacity > constDefaultCapacity)
capacity = constDefaultCapacity;
else
_str = _cached_str = String.Empty;
}
_maxCapacity = maxCapacity;
if (_str == null)
_str = String.InternalAllocateStr ((length > capacity) ? length : capacity);
if (length > 0)
String.CharCopy (_str, 0, value, startIndex, length);
_length = length;
}