findEndOfString method
Finds the end of a single line string constant.
end
specifies the string end (" or ').
If hasPrefixR
the string constant is a "raw string" that means meta chars
take not place there.
endPosition
: OUT the position behind the end delimiter.
Returns null on success, otherwise the error message.
Implementation
String? findEndOfString(
StringSearcher end, bool hasPrefixR, Position endPosition) {
int? ix;
String? rc;
final line = engine.lineByIndex(engine.currentPosition.line);
var col = engine.startColumnByIndex(engine.currentPosition.line);
col = engine.currentPosition.column > col
? engine.currentPosition.column
: col;
endPosition.clone(engine.currentPosition);
if (hasPrefixR) {
ix = end.next(line, col);
if (ix == null) {
rc = 'missing end of string (${end.toSearch}) in line: $line';
} else {
endPosition.column = ix + 1;
endPosition.normalize();
}
} else {
int? ix;
while (true) {
var found = false;
if ((ix = noMetaChar.next(line, col)) != null && ix == col) {
col = endPosition.column = ix! + engine.lastMatch.length();
found = true;
}
if (engine.containsAt(endPosition, backslash)) {
col = endPosition.column += 2;
found = true;
}
if (engine.containsAt(endPosition, end)) {
endPosition.column += end.toSearch.length;
endPosition.normalize();
break;
}
if (!found) {
rc = 'missing end of string (${end.toSearch}) in line: $line';
break;
}
}
}
return rc;
}