static TextEdit createTextEdit(S text, S newText) { S a = text, b = newText; int i = lCommonPrefix(a, b); if (i == l(a) && i == l(b)) null; // Strings are equal a = substring(a, i); b = substring(b, i); int j = lCommonSuffix(a, b); a = substring(a, 0, l(a)-j); b = substring(b, 0, l(b)-j); // Now differing part remains in a and b; // i and j give length of unchanged beginning+end if (empty(a) && empty(b)) null; TextEdit edit = nuWithParams(TextEdit, startIndex := i, endIndex := i+l(a), text := b); // Verify! assertEquals(newText, replayTextEdit(edit, text)); ret edit; }