1 | static TextEdit createTextEdit(S text, S newText) { |
2 | S a = text, b = newText; |
3 | int i = lCommonPrefix(a, b); |
4 | if (i == l(a) && i == l(b)) null; // Strings are equal |
5 | a = substring(a, i); |
6 | b = substring(b, i); |
7 | int j = lCommonSuffix(a, b); |
8 | a = substring(a, 0, l(a)-j); |
9 | b = substring(b, 0, l(b)-j); |
10 | |
11 | // Now differing part remains in a and b; |
12 | // i and j give length of unchanged beginning+end |
13 | if (empty(a) && empty(b)) null; |
14 | |
15 | TextEdit edit = nuWithParams(TextEdit, |
16 | startIndex := i, endIndex := i+l(a), text := b); |
17 | |
18 | // Verify! |
19 | assertEquals(newText, replayTextEdit(edit, text)); |
20 | |
21 | ret edit; |
22 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1009713 |
Snippet name: | createTextEdit - diff two text versions and create TextEdit - with verification |
Eternal ID of this version: | #1009713/2 |
Text MD5: | 2abc1f6a535112115a64461eb7333c9a |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-08-14 23:14:18 |
Source code size: | 641 bytes / 22 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 505 / 545 |
Version history: | 1 change(s) |
Referenced in: | [show references] |