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

22
LINES

< > BotCompany Repo | #1026162 // arbitraryVarsToStars

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2396L/15K).

sS arbitraryVarsToStars(S s, Set<S> vars, LS varNames_out) {
  if (empty(vars)) ret s;
  LS tok = javaTok(s);
  LS tok2 = arbitraryVarsToStars(tok, vars, varNames_out);
  ret tok == tok2 ? s : join(tok2);
}

static LS arbitraryVarsToStars(LS tok, Set<S> vars, LS varNames_out) {
  if (empty(vars)) ret tok;
  LS tok2 = null;
  int n = l(tok);
  for i to n: {
    S t = tok.get(i);
    if (odd(i) && vars.contains(t)) {
      listAdd(varNames_out, t);
      if (tok2 == null) tok2 = cloneSubList(tok, 0, i);
      tok2.add("*");
    } else
      if (tok2 != null) tok2.add(t);
  }
  ret tok2 != null ? tok2 : tok;
}

Author comment

Began life as a copy of #1010854

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1026162
Snippet name: arbitraryVarsToStars
Eternal ID of this version: #1026162/6
Text MD5: ab7fa29a7c86f710ae4ae9f664c5d20b
Transpilation MD5: 04fe41f109a72c01007662fe52bb51fb
Author: stefan
Category: javax / parsing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-11-28 13:53:02
Source code size: 635 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 221 / 332
Version history: 5 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1027388 - philosophyBot_varsToStars