getLineRange function

LineRange getLineRange(
  1. String file,
  2. String searchingText, [
  3. int postition = 0
])

Given a file and a string, find the line number of the string in the file.

  • file The file that we're searching in.
  • searchingText The text to search for.
  • position The position in the file to start searching from. Return A LineRange object.

Implementation

LineRange getLineRange(String file, String searchingText, [int postition = 0]) {
  final charAtStart = file.indexOf(searchingText, postition);
  final fileUpToStart = file.substring(0, charAtStart);

  final fileUpToEnd = file.substring(0, charAtStart + searchingText.length);
  return LineRange(
      fileUpToStart.split('\n').length - 1, fileUpToEnd.split('\n').length - 1);
}