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

24
LINES

< > BotCompany Repo | #1031419 // replaceKeywordBlock_dyn - finally the interface version we all want

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

Libraryless. Click here for Pure Java version (11242L/62K).

scope replaceKeywordBlock_dyn

sinterface #IReplacer {
  S[] get(LS tok, int iOpening, int iClosing);
}

static LS replaceKeywordBlock_dyn(S bracket default "{", LS tok, S keyword, IReplacer func) {
  for (int i = 0; i < 1000; i++) {
    int idx = findCodeTokens(tok, keyword, bracket);
    if (idx < 0)
      break;
    int j = findEndOfBracketPart(tok, idx+2);
    
    S[] be = func?.get(tok, idx+2, j-1);
    tok.set(idx, unnull(first(be)));
    tok.set(idx+1, " ");
    tok.set(idx+2, "");
    tok.set(j-1, unnull(second(be)));
    reTok(tok, idx, j);
  }
  ret tok;
}

end scope

Author comment

Began life as a copy of #1018806

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1031419
Snippet name: replaceKeywordBlock_dyn - finally the interface version we all want
Eternal ID of this version: #1031419/10
Text MD5: b1f297564a54ab21441b7331e37696bd
Transpilation MD5: 507125547f388fe729d20ce29c1ea4f0
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-07-26 21:59:38
Source code size: 607 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 202 / 400
Version history: 9 change(s)
Referenced in: [show references]