find method
The closer for the $ at i, or -1.
Implementation
int find(int i) {
if (i == _spent) {
return -1;
}
final n = text.length;
if (i > 0 && text.codeUnitAt(i - 1) == _dollarSign) {
return -1;
}
var k = i + 1;
if (k < n && text.codeUnitAt(k) == _dollarSign) {
return -1;
}
var blank = true;
while (k < n) {
final c = text.codeUnitAt(k);
if (c == 0x0A) {
return -1;
}
if (c == _dollarSign && text.codeUnitAt(k - 1) != _backslashChar) {
break;
}
if (blank && !isUnicodeWhitespace(c)) {
blank = false;
}
k += 1;
}
if (k >= n || blank) {
return -1;
}
if (k + 1 < n && text.codeUnitAt(k + 1) == _dollarSign) {
return -1;
}
if ((leadsPrice(text, i) && leadsPrice(text, k)) ||
(followsPrice(text, i) && followsPrice(text, k))) {
_spent = k;
return -1;
}
return k;
}