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

24
LINES

< > BotCompany Repo | #1023231 // replaceOrDropCodeTokensUsingMap - drops token on empty value [dev.]

JavaX fragment (include)

1  
static S replaceOrDropCodeTokensUsingMap(S s, SS map) {
2  
  ret join(replaceOrDropCodeTokensUsingMap(javaTok(s), map);
3  
}
4  
5  
static LS replaceOrDropCodeTokensUsingMap(LS tok, SS map) {
6  
  LS out = emptyList(tok);
7  
  for i over tok: {
8  
    if (odd(i)) out.add(tok.get(i));
9  
    else {
10  
      S val = lookupOrKeep(map, tok.get(i));
11  
      if (nempty(val))
12  
        out.add(val);
13  
      else {
14  
        out.add(ai_mergeWhitespace(last(out), tok.get(i+1)));
15  
        i++;
16  
      }
17  
    }
18  
  }
19  
  ret out;
20  
}
21  
22  
sS replaceOrDropCodeTokensUsingMap(SS map, S s) {
23  
  ret replaceOrDropCodeTokensUsingMap(s, map);
24  
}

Author comment

Began life as a copy of #1014558

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1023231
Snippet name: replaceOrDropCodeTokensUsingMap - drops token on empty value [dev.]
Eternal ID of this version: #1023231/3
Text MD5: 081792eea64aba59023a3b81a2e4e2f3
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-05-18 13:42:38
Source code size: 606 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 166 / 193
Version history: 2 change(s)
Referenced in: [show references]