firstMatch method

Match? firstMatch(
  1. String input, {
  2. bool longest = false,
})

returns the first match or null if none was found optionally you can specify longest: true to search for the longest match at a specific position. If you have the words ['abc', 'abcd'] and your text is 'abcd' the longest parameter will not fire when it finds 'abc' but after it checked enough positions to find all possible longer words and then return 'abcd'

Implementation

Match? firstMatch(String input, {bool longest = false}) {
  final fullInput = separateBySpaces ? ' $input ' : input;
  if (longest) {
    return _fixShiftedMatch(_firstMatchLongest(fullInput));
  }
  final state = stateMachine.createState();
  for (var i = 0; i < fullInput.length; i++) {
    state.performStep(fullInput[i]);
    if (state.activeStateIsSuccess) {
      final word = state.activeState.words.first;
      return _fixShiftedMatch(
          Match(startIndex: i - word.length + 1, word: word));
    }
  }
  return null;
}