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

27
LINES

< > BotCompany Repo | #1000585 // LInputPatternPrefixSuffix (learner, developing)

JavaX fragment (include)

// for "find" tasks (e.g. "abcde" to "[[abc]]de")
static class LInputPatternPrefixSuffix extends LearnerImpl {
  String findMarker1 = "[[", findMarker2 = "]]";
  String prefix, suffix;
  
  public void processInOut(Object _in, Object _out) {
    String in = (String) _in, out = (String) _out;
    findMarkedStrings();
    int i = out.indexOf(findMarker1), j = out.indexOf(findMarker2, i+1);
    if (j < 0) return;
    String s = out.substring(i+2, j);
    regexp = s.replaceAll("\\d+", Matcher.quoteReplacement("\\d+"));
    System.out.println("regexp: " + regexp);
  }
  
  public String processIn(Object _in) {
    String in = (String) _in;
    if (regexp.length() == 0)
      return in;
    else
      return in.replaceAll("(" + regexp + ")", findMarker1 + "$1" + findMarker2);
  }
  
  public void toJava(Code code) {
    code.line(code.var + " = ((String) " + code.var + ").replaceAll(" + quote("(" + regexp + ")") + ", \"[[$1]]\");");
  }
}

Author comment

Began life as a copy of #1000584

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

2 comment(s) hidden. show

Snippet ID: #1000585
Snippet name: LInputPatternPrefixSuffix (learner, developing)
Eternal ID of this version: #1000585/1
Text MD5: 582d6c55a2fd9b44970c38e401040cd9
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-08-15 00:08:22
Source code size: 972 bytes / 27 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 1081 / 971
Referenced in: [show references]