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

43
LINES

< > BotCompany Repo | #1022728 // jreplace - before last change

JavaX fragment (include)

1  
meta-postProcess { tok_jreplace_standardParameter }
2  
3  
static S jreplace(S s, S in, S out) {
4  
  ret jreplace(s, in, out, null);
5  
}
6  
7  
static S jreplace(S s, S in, S out, O condition) {
8  
  L<S> tok = javaTok(s);
9  
  ret jreplace(tok, in, out, condition) ? join(tok) : s;
10  
}
11  
12  
// leaves tok properly tokenized
13  
// returns true iff anything was replaced
14  
static boolean jreplace(L<S> tok, S in, S out) {
15  
  ret jreplace(tok, in, out, false, true, null);
16  
}
17  
18  
static boolean jreplace(L<S> tok, S in, S out, O condition) {
19  
  ret jreplace(tok, in, out, false, true, condition);
20  
}
21  
22  
static boolean jreplace(L<S> tok, S in, S out, boolean ignoreCase, boolean reTok, O condition) {
23  
  S[] toks = javaTokForJFind_array(in);
24  
  int lTokin = toks.length*2+1;
25  
26  
  boolean anyChange = false;
27  
  for (int n = 0; n < 10000; n++) {
28  
    int i = findCodeTokens(tok, 1, ignoreCase, toks, condition);
29  
    if (i < 0)
30  
      ret anyChange;
31  
    L<S> subList = tok.subList(i-1, i+lTokin-1); // N to N
32  
    S expansion = jreplaceExpandRefs(out, subList);
33  
    int end = i+lTokin-2;
34  
    clearAllTokens(tok, i, end); // C to C
35  
    tok.set(i, expansion);
36  
    if (reTok) // would this ever be false??
37  
      reTok(tok, i, end);
38  
    anyChange = true;
39  
  }
40  
  throw fail("woot? 10000! " + quote(in) + " => " + quote(out));
41  
}
42  
43  
static bool jreplace_debug;

Author comment

Began life as a copy of #1002133

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: #1022728
Snippet name: jreplace - before last change
Eternal ID of this version: #1022728/1
Text MD5: b134741d21c029d4f74ffedd88e17b3f
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-04-03 15:40:35
Source code size: 1336 bytes / 43 lines
Pitched / IR pitched: No / No
Views / Downloads: 232 / 266
Referenced in: [show references]