1 | // for "find" tasks (e.g. "abcde" to "[[abc]]de") |
2 | static class LInputPattern extends LearnerImpl {
|
3 | static boolean debug; |
4 | String regexp = "", findMarker1 = "[[", findMarker2 = "]]"; |
5 | |
6 | public void processInOut(Object _in, Object _out) {
|
7 | String in = (String) _in, out = (String) _out; |
8 | int i = out.indexOf(findMarker1), j = out.indexOf(findMarker2, i+1); |
9 | if (j < 0) return; |
10 | String s = out.substring(i+2, j); |
11 | regexp = s.replaceAll("\\d+", Matcher.quoteReplacement("\\d+"));
|
12 | if (debug) |
13 | debug("regexp: " + regexp);
|
14 | } |
15 | |
16 | public String processIn(Object _in) {
|
17 | String in = (String) _in; |
18 | if (regexp.length() == 0) |
19 | return in; |
20 | else |
21 | return in.replaceAll("(" + regexp + ")", findMarker1 + "$1" + findMarker2);
|
22 | } |
23 | |
24 | public void toJava(Code code) {
|
25 | code.line(code.var + " = ((String) " + code.var + ").replaceAll(" + quote("(" + regexp + ")") + ", \"[[$1]]\");");
|
26 | } |
27 | } |
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
| ID | Author/Program | Comment | Date | |
|---|---|---|---|---|
| 439 | #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 LInputPattern extends LearnerImpl { static boolean debug; String regexp = "", findMarker1 = "[[", findMarker2 = "]]"; public void processInOut(Object _in, Object _out) { String in = (String) _in, out = (String) _out; 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+")); if (debug) debug("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 14:40:56 | delete |
| 436 | #1000604 (pitcher) | 2015-08-18 14:40:29 |
| Snippet ID: | #1000584 |
| Snippet name: | LInputPattern (learner) |
| Eternal ID of this version: | #1000584/1 |
| Text MD5: | 586a51fe7c20d4110db5e5492aacb90e |
| Author: | stefan |
| Category: | |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2015-08-18 14:40:29 |
| Source code size: | 951 bytes / 27 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 1405 / 1975 |
| Referenced in: | [show references] |