find method
The closer for the $ at i, or -1.
Implementation
int find(int i) {
final n = text.length;
if (i + 1 >= n || isUnicodeWhitespace(text.codeUnitAt(i + 1))) {
return -1;
}
if (_failedFrom != -1 && i >= _failedFrom && i < _failedUntil) {
return -1;
}
var limit = n;
if (sameLine) {
final lineEnd = text.indexOf('\n', i);
if (lineEnd != -1) {
limit = lineEnd;
}
}
final next = text.codeUnitAt(i + 1);
final digitLed = next >= 0x30 && next <= 0x39;
var searchLimit = limit;
if (digitLed) {
var w = i + 1;
while (w < limit && !isUnicodeWhitespace(text.codeUnitAt(w))) {
w += 1;
}
searchLimit = w;
}
var k = text.indexOf(r'$', i + 1);
while (k != -1 && k < searchLimit) {
final before = text.codeUnitAt(k - 1);
final after = k + 1 < n ? text.codeUnitAt(k + 1) : -1;
if (k > i + 1 &&
before != 0x5C /* \ */ &&
before != 0x24 /* $ */ &&
after != 0x24 &&
!isUnicodeWhitespace(before) &&
!(after >= 0x30 && after <= 0x39)) {
return k;
}
k = text.indexOf(r'$', k + 1);
}
if (!digitLed) {
_failedFrom = i;
_failedUntil = limit;
}
return -1;
}