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

56
LINES

< > BotCompany Repo | #1002133 // jreplace

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

Libraryless. Click here for Pure Java version (9819L/55K).

meta-postProcess { tok_jreplace_standardParameter }

static S jreplace(S s, S in, S out) {
  ret jreplace(s, in, out, null);
}

static S jreplace(S s, S in, S out, O condition) {
  LS tok = javaTok(s);
  ret jreplace(tok, in, out, condition) ? join(tok) : s;
}

// leaves tok properly tokenized
// returns true iff anything was replaced
static boolean jreplace(LS tok, S in, S out) {
  ret jreplace(tok, in, out, false, true, null);
}

static boolean jreplace(LS tok, S in, S out, O condition) {
  ret jreplace(tok, in, out, false, true, condition);
}

sbool jreplace(LS tok, S in, ITokCondition condition, S out) {
  ret jreplace(tok, in, out, (O) condition);
}

sbool jreplace(LS tok, S in, S out, IF2<LS, Int, Bool> condition) {
  ret jreplace(tok, in, out, (O) condition);
}

sbool jreplace(LS tok, S in, S out, boolean ignoreCase, bool reTok, O condition) {
  S[] toks = javaTokForJFind_array(in);
  int lTokin = toks.length*2+1;

  boolean anyChange = false;
  int i = -1;
  for (int n = 0; n < 10000; n++) { // TODO: don't need this check anymore
    i = findCodeTokens(tok, i+1, ignoreCase, toks, condition);
    if (i < 0)
      ret anyChange;
    LS subList = tok.subList(i-1, i+lTokin-1); // N to N
    S expansion = jreplaceExpandRefs(out, subList);
    int end = i+lTokin-2;
    ifdef jreplace_performing
    jreplace_performing(tok, i, end, expansion);
    endifdef
    clearAllTokens(tok, i, end); // C to C
    tok.set(i, expansion);
    if (reTok) // would this ever be false??
      reTok(tok, i, end);
    i = end;
    anyChange = true;
  }
  throw fail("woot? 10000! " + quote(in) + " => " + quote(out));
}

static bool jreplace_debug;

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1002133
Snippet name: jreplace
Eternal ID of this version: #1002133/11
Text MD5: 2223ca74e842f420b2a38ee1f8945714
Transpilation MD5: a780dbe2391eb0c0cf7b50794b4ea92a
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-06-16 17:12:11
Source code size: 1710 bytes / 56 lines
Pitched / IR pitched: No / No
Views / Downloads: 864 / 2298
Version history: 10 change(s)
Referenced in: [show references]