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

35
LINES

< > BotCompany Repo | #1008358 // jreplaceStart - replace first tokens only

JavaX fragment (include)

1  
static S jreplaceStart(S s, S in, S out) {
2  
  ret jreplaceStart(s, in, out, null);
3  
}
4  
5  
static S jreplaceStart(S s, S in, S out, O condition) {
6  
  L<S> tok = javaTok(s);
7  
  jreplaceStart(tok, in, out, condition);
8  
  ret join(tok);
9  
}
10  
11  
// leaves tok properly tokenized
12  
// returns true iff anything was replaced
13  
static boolean jreplaceStart(L<S> tok, S in, S out) {
14  
  ret jreplaceStart(tok, in, out, false, false, null);
15  
}
16  
17  
static boolean jreplaceStart(L<S> tok, S in, S out, O condition) {
18  
  ret jreplaceStart(tok, in, out, false, false, condition);
19  
}
20  
21  
static boolean jreplaceStart(L<S> tok, S in, S out, boolean ignoreCase, boolean reTok, O condition) {
22  
  L<S> tokin = javaTok(in);
23  
  jfind_preprocess(tokin);
24  
25  
  int i = findCodeTokens(tok, 1, ignoreCase, toStringArray(codeTokensOnly(tokin)), condition); // TODO: opt
26  
  if (i != 1) false;
27  
  L<S> subList = tok.subList(i-1, i+l(tokin)-1); // N to N
28  
  S expansion = jreplaceExpandRefs(out, subList);
29  
  int end = i+l(tokin)-2;
30  
  clearAllTokens(tok, i, end); // C to C
31  
  tok.set(i, expansion);
32  
  if (reTok)
33  
    reTok(tok, i, end);
34  
  true;
35  
}

Author comment

Began life as a copy of #1002133

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1008358
Snippet name: jreplaceStart - replace first tokens only
Eternal ID of this version: #1008358/1
Text MD5: 706d97441481fc814a1fcd6b7112563f
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-05-09 17:03:55
Source code size: 1113 bytes / 35 lines
Pitched / IR pitched: No / No
Views / Downloads: 379 / 402
Referenced in: [show references]