indexOf method

  1. @override
int indexOf(
  1. String string,
  2. int start
)
override

Returns the index of the starting position of the found string, otherwise returns the value -1.

The search begins at offset start, the value must be specified in units defined for a specific reader.

Implementation

@override
int indexOf(String string, int start) {
  _lastIndex = -1;
  _readDataSize = 0;
  if (start >= length) {
    return -1;
  }

  if (string.isEmpty) {
    return start;
  }

  final first = string.runeAt(0);
  var readDataSize = 0;
  var index = start;
  while (index < length) {
    final c = _read(index);
    index += _readDataSize;
    readDataSize += _readDataSize;
    if (c != first) {
      continue;
    }

    if (string.length == 1) {
      _lastIndex = -1;
      _readDataSize = readDataSize;
      return index;
    }

    if (startsWith(string, index)) {
      _lastIndex = -1;
      _readDataSize = readDataSize;
      return index;
    }
  }

  _lastIndex = -1;
  _readDataSize = 0;
  return -1;
}