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

13
LINES

< > BotCompany Repo | #1002443 // findBeginningOfBlock

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (54L/1K).

// i must point at the (possibly imaginary) closing bracket
// index returned is index of opening bracket
static int findBeginningOfBlock(LS cnc, int i) {
  int j = i-2, level = 1;
  while (j > 0) {
    if (eq(cnc.get(j), "}")) ++level;
    else if (eq(cnc.get(j), "{")) --level;
    if (level == 0)
      ret j;
    j -= 2;
  }
  ret -1;
}

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

No comments. add comment

Snippet ID: #1002443
Snippet name: findBeginningOfBlock
Eternal ID of this version: #1002443/4
Text MD5: 749911dbf4a809f848346152ded5367d
Transpilation MD5: 0ecb11806590e126709446aceedab8e1
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-11-04 12:13:57
Source code size: 352 bytes / 13 lines
Pitched / IR pitched: No / No
Views / Downloads: 614 / 598
Version history: 3 change(s)
Referenced in: [show references]