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

19
LINES

< > BotCompany Repo | #1002188 // mapBasedReplace

JavaX fragment (include)

1  
// themap is the replacement map in list form - in/out/in/out/...
2  
static S mapBasedReplace(L<S> themap, S s) {
3  
  L<S> tok = javaTok(s);
4  
  for (int i = 1; i < l(tok); i += 2) {
5  
    for (int j = 0; j < l(themap); j += 2) {
6  
      S x = themap.get(j), y = themap.get(j+1);
7  
      L<S> tokx = javaTok(x), toky = javaTok(y);
8  
      mapBasedReplace_matchReplace(tok, i, tokx, toky);
9  
    }
10  
  }
11  
  ret join(tok);
12  
}
13  
14  
static void mapBasedReplace_matchReplace(L<S> tok, int i, L<S> tokx, L<S> toky) {
15  
  if (tokRegionMatchIC(tok, i, tokx)) {
16  
    clearAllTokens(tok.subList(i, i+l(tokx)-2));
17  
    tok.set(i, join(toky));
18  
  }
19  
}

Author comment

Began life as a copy of #1002187

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: #1002188
Snippet name: mapBasedReplace
Eternal ID of this version: #1002188/1
Text MD5: 71cd16b9e64c9fe17deb379efd437dfe
Author: stefan
Category: nl
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-12-24 00:27:54
Source code size: 628 bytes / 19 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 688 / 897
Referenced in: [show references]