followsPrice function

bool followsPrice(
  1. String text,
  2. int i
)

Whether the $ at i directly follows an amount (5$, 9.99$, 1,000$) that starts a word, and ends its own word.

Implementation

bool followsPrice(String text, int i) {
  var k = i - 1;
  if (k < 0 || !_isDigit(text.codeUnitAt(k))) {
    return false;
  }
  while (k >= 0) {
    final c = text.codeUnitAt(k);
    if (_isDigit(c)) {
      k -= 1;
    } else if ((c == 0x2C || c == 0x2E) &&
        k > 0 &&
        _isDigit(text.codeUnitAt(k - 1))) {
      k -= 2;
    } else {
      break;
    }
  }
  if (k >= 0 && _isWordPart(text.codeUnitAt(k))) {
    return false;
  }
  return _endsWord(text, i + 1);
}