Libraryless. Click here for Pure Java version (94L/2K/4K).
// Syntax: dialogHandler { doSomething(io); } !592 1000265 // auto-importer, standard function adder public class main { public static void main(String[] args) throws Exception { String s = loadMainJava(); Pattern regex = Pattern.compile("dialogHandler\\s*\\{"); for (int i = 0; i < 100; i++) { Matcher matcher = regex.matcher(s); if (!matcher.find()) break; System.out.println("Iteration " + (i+1)); int start = matcher.start(), end = matcher.end(); int endOfBlock = findEndOfBlock(s, end); String listener = "new DialogHandler() {\n" + "public void run(final DialogIO io) {\n" + s.substring(end, endOfBlock) + "\n}"; s = s.substring(0, start) + listener + s.substring(endOfBlock); } saveMainJava(s); } // start is the index AFTER the opening bracket // returns index OF closing bracket static int findEndOfBlock(String s, int start) { int level = 1; for (int i = start; i < s.length(); i++) { if (s.charAt(i) == '{') ++level; else if (s.charAt(i) == '}') --level; if (level == 0) return i; } return s.length(); } }
Began life as a copy of #614
download show line numbers debug dex old transpilations
Travelled to 17 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, jlatgrcjtklg, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1000868 |
Snippet name: | "dialogHandler {" short-hand (JavaX translator) |
Eternal ID of this version: | #1000868/1 |
Text MD5: | 1859a8dbdd118d77f1207ba1394286c5 |
Transpilation MD5: | 41cb094ca1d07ede15f9e4458eed289c |
Author: | stefan |
Category: | |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-09-24 21:06:39 |
Source code size: | 1225 bytes / 41 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 794 / 4405 |
Referenced in: | [show references] |