Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

22
LINES

< > BotCompany Repo | #1009713 // createTextEdit - diff two text versions and create TextEdit - with verification

JavaX fragment (include)

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;
}

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: 506 / 545
Version history: 1 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)