search method

List<int> search(
  1. String substring, {
  2. bool caseSensitive = false,
  3. bool wholeWord = false,
})

Search given substring in the whole document Supports caseSensitive and wholeWord options Returns correspondent offsets

Implementation

List<int> search(
  String substring, {
  bool caseSensitive = false,
  bool wholeWord = false,
}) {
  final matches = <int>[];
  for (final node in _root.children) {
    if (node is Line) {
      _searchLine(substring, caseSensitive, wholeWord, node, matches);
    } else if (node is Block) {
      for (final line in Iterable.castFrom<dynamic, Line>(node.children)) {
        _searchLine(substring, caseSensitive, wholeWord, line, matches);
      }
    } else {
      throw StateError('Unreachable.');
    }
  }
  return matches;
}