leadsPrice function

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

Whether the $ at i is directly followed by an amount: digits, with , groups and a . fraction (5, 1,000, 9.99), an optional size suffix (k, K, M, B, bn, m), then the end of the word.

Implementation

bool leadsPrice(String text, int i) {
  final n = text.length;
  var k = i + 1;
  if (k >= n || !_isDigit(text.codeUnitAt(k))) {
    return false;
  }
  while (k < n) {
    final c = text.codeUnitAt(k);
    if (_isDigit(c)) {
      k += 1;
    } else if ((c == 0x2C /* , */ || c == 0x2E /* . */ ) &&
        k + 1 < n &&
        _isDigit(text.codeUnitAt(k + 1))) {
      k += 2;
    } else {
      break;
    }
  }
  if (k < n) {
    final c = text.codeUnitAt(k);
    if (c == 0x62 /* b */ && k + 1 < n && text.codeUnitAt(k + 1) == 0x6E) {
      k += 2; // bn
    } else if (c == 0x6B /* k */ ||
        c == 0x4B /* K */ ||
        c == 0x4D /* M */ ||
        c == 0x42 /* B */ ||
        c == 0x6D /* m */ ) {
      k += 1;
    }
  }
  return _endsWord(text, k);
}