1 | // for "find" tasks (e.g. "abcde" to "[[abc]]de") |
2 | static class LInputPatternPrefixSuffix extends LearnerImpl { |
3 | String findMarker1 = "[[", findMarker2 = "]]"; |
4 | String prefix, suffix; |
5 | |
6 | public void processInOut(Object _in, Object _out) { |
7 | String in = (String) _in, out = (String) _out; |
8 | findMarkedStrings(); |
9 | int i = out.indexOf(findMarker1), j = out.indexOf(findMarker2, i+1); |
10 | if (j < 0) return; |
11 | String s = out.substring(i+2, j); |
12 | regexp = s.replaceAll("\\d+", Matcher.quoteReplacement("\\d+")); |
13 | System.out.println("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 | } |
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: | 1339 / 1233 |
Referenced in: | [show references] |