Libraryless. Click here for Pure Java version (1356L/9K/30K).
1 | !752 |
2 | |
3 | /*static class Bracket { |
4 | int iOp, iCl; // indices of opening and closing bracket |
5 | }*/ |
6 | |
7 | p { |
8 | L<S> tok = javaTok(loadSnippet("#1002114")); |
9 | new L<int> stack; |
10 | new L<L<S>> parts; |
11 | boolean match = true; |
12 | for (int i = 1; i < l(tok); i+= 2) { |
13 | if (litlist("{", "(").contains(tok.get(i))) |
14 | stack.add(i); |
15 | else if (litlist("}", ")").contains(tok.get(i))) { |
16 | if (empty(stack)) match = false; |
17 | else parts.add(tok.subList(liftLast(stack), i+2)); |
18 | } |
19 | } |
20 | |
21 | if (!empty(stack)) match = false; |
22 | print(match ? "Brackets match." : "Brackets do not match."); |
23 | |
24 | for (L<S> part : parts) |
25 | print(quote(join(part))); |
26 | } |
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1002115 |
Snippet name: | Find brackets in C++ |
Eternal ID of this version: | #1002115/1 |
Text MD5: | 89be4ad15eb1d14dbeeed7931604c971 |
Transpilation MD5: | 5d3aaf2b63ae4dfec8a46507285cb63b |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-12-19 01:37:03 |
Source code size: | 667 bytes / 26 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 644 / 682 |
Referenced in: | [show references] |