getSearchTermFromIndex method

String getSearchTermFromIndex(
  1. {required String text,
  2. required int index}
)

Gets a search term and for a space-delimited language, assumes the index is within the range of the first word, with remainder words included. For a language that is not space-delimited, this is simply the substring function.

Implementation

String getSearchTermFromIndex({
  required String text,
  required int index,
}) {
  if (isSpaceDelimited) {
    final workingBuffer = StringBuffer();
    final termBuffer = StringBuffer();
    List<String> words = textToWords(text.replaceAll('\n', ' '));

    for (String word in words) {
      workingBuffer.write(word);
      if (workingBuffer.length > index) {
        termBuffer.write(word);
      }
    }

    return termBuffer.toString();
  } else {
    return text.substring(index);
  }
}