subSequence method

  1. @override
String subSequence(
  1. int start,
  2. int end
)
override

Returns a CharSequence that is a subsequence of this sequence. The subsequence starts with the char value at the specified index and ends with the char value at index end - 1. The length (in chars) of the returned sequence is end - start, so if start == end then an empty sequence is returned.

@param start the start index, inclusive @param end the end index, exclusive

@return the specified subsequence

@throws IndexOutOfBoundsException if start or end are negative, if end is greater than length, or if start is greater than end @throws IllegalArgumentException if a value in the range start-end is an ECI (@see #isECI)

Implementation

@override
String subSequence(int start, int end) {
  if (start < 0 || start > end || end > length) {
    //IndexOutOfBoundsException
    throw IndexError.withLength(start, length);
  }
  final result = StringBuffer();
  for (int i = start; i < end; i++) {
    if (isECI(i)) {
      // IllegalArgumentException
      throw ArgumentError(
        'value at $i (${charAt(i)}) is not a character but an ECI',
      );
    }
    result.writeCharCode(charAt(i));
  }
  return result.toString();
}