compareString static method
Implementation
static ({String character, int index, bool isAddText}) compareString(String oldText, String newText) {
final isAddText = newText.length > oldText.length;
final longerText = isAddText ? newText : oldText;
final shorterText = isAddText ? oldText : newText;
int diffIndex = -1;
for (int i = 0; i < shorterText.length; i++) {
if (longerText[i] != shorterText[i]) {
diffIndex = i;
break;
}
}
if (diffIndex == -1) {
diffIndex = shorterText.length;
}
String characters = longerText.substring(diffIndex, longerText.length - shorterText.length + diffIndex);
return (
character: characters,
index: diffIndex,
isAddText: isAddText,
);
}