Libraryless. Click here for Pure Java version (5052L/28K).
// i must point at the (possibly imaginary) opening bracket ("{") // index returned is index of closing bracket + 1 (or l(tok)) // TODO: could use iterator to be even faster static int tok_findEndOfBlock_IContentsIndexedList2(IContentsIndexedList2<S> tok, int i) { int n = l(tok); // find opening & closing brackets after start index TreeSet<HasIndex> openers = tok.indicesOf_treeSetOfHasIndex("{"); TreeSet<HasIndex> closers = tok.indicesOf_treeSetOfHasIndex("}"); // now step through both sets int level = 1; HasIndex start = new(i); HasIndex nextOpener = openers.higher(start); HasIndex nextCloser = closers.higher(start); while true { if (nextCloser == null) ret n; // block isn't closed if (nextOpener != null && nextOpener.idx < nextCloser.idx) { // process opener ++level; nextOpener = openers.higher(nextOpener); } else { // process closer if (--level == 0) ret nextCloser.idx+1; nextCloser = closers.higher(nextCloser); } } }
Began life as a copy of #1025221
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034666 |
Snippet name: | tok_findEndOfBlock_IContentsIndexedList2 |
Eternal ID of this version: | #1034666/3 |
Text MD5: | 5ff30397f2d98fb74710d6da5c60d34a |
Transpilation MD5: | 6b39a5c815a279a849f9ffe4f09caa7b |
Author: | stefan |
Category: | javax / transpiling |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-03-01 15:50:59 |
Source code size: | 1068 bytes / 35 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 165 / 225 |
Version history: | 2 change(s) |
Referenced in: | [show references] |