Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

26
LINES

< > BotCompany Repo | #1002115 // Find brackets in C++

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (1356L/9K/30K).

!752

/*static class Bracket {
  int iOp, iCl; // indices of opening and closing bracket
}*/

p {
  L<S> tok = javaTok(loadSnippet("#1002114"));
  new L<int> stack;
  new L<L<S>> parts;
  boolean match = true;
  for (int i = 1; i < l(tok); i+= 2) {
    if (litlist("{", "(").contains(tok.get(i)))
      stack.add(i);
    else if (litlist("}", ")").contains(tok.get(i))) {
      if (empty(stack)) match = false;
      else parts.add(tok.subList(liftLast(stack), i+2));
    }
  }
  
  if (!empty(stack)) match = false;
  print(match ? "Brackets match." : "Brackets do not match.");
  
  for (L<S> part : parts)
    print(quote(join(part)));
}

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