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

23
LINES

< > BotCompany Repo | #1033719 // replaceKeywordPlusQuotedBlock_dyn

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

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

scope replaceKeywordPlusQuotedBlock_dyn

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

// finds "<keyword> <quoted> {"
// func: tok, iKeyword -> S[] {beg, end}
static LS replaceKeywordPlusQuotedBlock_dyn(LS tok, S keyword, IReplacer f) {
  for (int i = 0; i < 1000; i++) {
    int idx = jfind(tok, keyword + " <quoted> {");
    if (idx < 0)
      break;
    int j = findEndOfBracketPart(tok, idx+4);
    
    S[] be = f.get(tok, idx);
    tok.set(idx, be[0]);
    clearTokens(tok, idx+1, idx+5);
    tok.set(j-1, be[1]);
    reTok(tok, idx, j);
  }
  ret tok;
}

Author comment

Began life as a copy of #1009010

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033719
Snippet name: replaceKeywordPlusQuotedBlock_dyn
Eternal ID of this version: #1033719/1
Text MD5: e98a9918b7e66e1548a0d14932811b44
Transpilation MD5: df195c9653c72452f707ca98d86656d3
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-12-28 20:41:49
Source code size: 597 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 128 / 185
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)