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)

static S replaceOrDropCodeTokensUsingMap(S s, SS map) {
  ret join(replaceOrDropCodeTokensUsingMap(javaTok(s), map);
}

static LS replaceOrDropCodeTokensUsingMap(LS tok, SS map) {
  LS out = emptyList(tok);
  for i over tok: {
    if (odd(i)) out.add(tok.get(i));
    else {
      S val = lookupOrKeep(map, tok.get(i));
      if (nempty(val))
        out.add(val);
      else {
        out.add(ai_mergeWhitespace(last(out), tok.get(i+1)));
        i++;
      }
    }
  }
  ret out;
}

sS replaceOrDropCodeTokensUsingMap(SS map, S s) {
  ret replaceOrDropCodeTokensUsingMap(s, map);
}

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: 162 / 187
Version history: 2 change(s)
Referenced in: [show references]