headEquals method
Returns this
String head part that is equals to other
.
- If
splitIndexes
is provided the head String can only be split at this indexes.
Implementation
String headEquals(String other,
{List<int>? splitIndexes, bool splitIndexesAlreadySorted = false}) {
var head = headEqualsLength(other);
if (head == 0) return '';
if (head == length) return this;
if (splitIndexes != null && splitIndexes.isNotEmpty) {
if (!splitIndexesAlreadySorted) {
splitIndexes = splitIndexes.toList();
splitIndexes.sort();
}
var idx = splitIndexes.searchInsertSortedIndex(head);
if (idx >= splitIndexes.length) idx = splitIndexes.lastIndex;
var split = splitIndexes[idx];
if (idx == 0) {
if (head < split) {
return '';
} else {
head = split;
}
} else if (idx == splitIndexes.lastIndex) {
if (head < split) {
head = splitIndexes[idx - 1];
} else {
head = split;
}
} else {
if (head != split) {
head = splitIndexes[idx - 1];
}
}
}
var s = substring(0, head);
return s;
}