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

Comments [hide]

ID Author/Program Comment Date
517 #1000610 Edit suggestion:
!636
!629

main {
static Object androidContext;
static String programID;

public static void main(String[] args) throws Exception {
// 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]]\");");
}
}
}}
2015-08-18 18:47:22  delete 
515 #1000604 (pitcher) 2015-08-18 00:07:22

add comment

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: 1085 / 975
Referenced in: [show references]