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) { L 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(L tok, S in, S out) { ret jreplace(tok, in, out, false, true, null); } static boolean jreplace(L tok, S in, S out, O condition) { ret jreplace(tok, in, out, false, true, condition); } static boolean jreplace(L tok, S in, S out, boolean ignoreCase, boolean reTok, O condition) { L tokin = javaTok(in); jfind_preprocess(tokin); S[] toks = toStringArray(codeTokensOnly(tokin)); boolean anyChange = false; for (int n = 0; n < 10000; n++) { int i = findCodeTokens(tok, 1, ignoreCase, toks, condition); if (i < 0) ret anyChange; L 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); anyChange = true; } throw fail("woot? 10000! " + quote(in) + " => " + quote(out)); } static bool jreplace_debug;