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

40
LINES

< > BotCompany Repo | #1004948 - jreplace1 - go through code just once

JavaX fragment (include)

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

static S jreplace1(S s, S in, S out, O condition) {
  L<S> tok = javaTok(s);
  ret jreplace1(tok, in, out, condition) ? join(tok) : s;
}

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

static boolean jreplace1(L<S> tok, S in, S out, O condition) {
  ret jreplace1(tok, in, out, false, true, condition);
}

static boolean jreplace1(L<S> tok, S in, S out, boolean ignoreCase, boolean reTok, O condition) {
  L<S> tokin = javaTok(in);
  jfind_preprocess(tokin);

  boolean anyChange = false;
  int i = 1;
  while ((i = findCodeTokens(tok, i, ignoreCase, toStringArray(codeTokensOnly(tokin)), condition)) >= 0) {
    L<S> subList = tok.subList(i-1, i+l(tokin)-1); // N to N
    S expansion = jreplaceExpandRefs(out, subList);
    int end = i+l(tokin)-2;
    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;
  }
  ret anyChange;
}

static bool jreplace1_debug;

Author comment

Began life as a copy of #1002133

download  show line numbers  debug dex   

Travelled to 11 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #1004948
Snippet name: jreplace1 - go through code just once
Eternal ID of this version: #1004948/3
Text MD5: 32af05e1f1b0c3bfa91c8a771d5b9a7d
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-11-06 18:04:41
Source code size: 1225 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 333 / 433
Version history: 2 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1004948 & http://1004948.tinybrain.de