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

19
LINES

< > BotCompany Repo | #1000470 // "bla" as ".+" with outPattern (learner)

JavaX fragment (include)

1  
static class LBla extends LearnerImpl {
2  
  static boolean debug;
3  
  String inPattern, outPattern;
4  
5  
  public void processInOut(Object _in, Object _out) {
6  
    String in = (String) _in, out = (String) _out;
7  
    int i = in.indexOf("bla"), j = out.indexOf("bla");
8  
    if (i < 0 || j < 0) fail();
9  
    inPattern = "^" + patternQuote(in.substring(0, i))
10  
      + "(.+)" + patternQuote(in.substring(i+3)) + "$";
11  
    outPattern = Matcher.quoteReplacement(out.substring(0, j))
12  
      + "$1" + Matcher.quoteReplacement(out.substring(j+3));
13  
  }
14  
  
15  
  public Object processIn(Object _in) {
16  
    String in = (String) _in;
17  
    return in.replaceAll(inPattern, outPattern);
18  
  }
19  
}

Author comment

Began life as a copy of #1000468

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1000470
Snippet name: "bla" as ".+" with outPattern (learner)
Eternal ID of this version: #1000470/1
Text MD5: 3fafde567ae4a19b3ff5b7d9e9371b94
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-08-09 16:35:51
Source code size: 673 bytes / 19 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 796 / 1969
Referenced in: [show references]