Libraryless. Click here for Pure Java version (2796L/18K).
// pred receives the params of opening tag as string (e.g. <if $bla> => "$bla") sS html_evaluateIfTags(S html, IPred<S> pred) { LS tok = htmlTok(html); bool anyChange; while ping (true) { LS ifTag = first(findContainerTag(tok, "if")); if (ifTag == null) break; set anyChange; int iElse = indexOfIC(ifTag, "<else>"); bool val = pred.get(htmlTagFullParamString(second(ifTag))); if (val) { // value is true, drop else branch (if there) if (iElse >= 0) clearTokens(ifTag, iElse, l(ifTag)-2); } else { // value is false, drop everything up until <else> (or whole thing) clearTokens(ifTag, 2, iElse < 0 ? l(ifTag) - 2 : iElse+1); } // clear opening and closing tag clearToken(ifTag, 1); clearToken(ifTag, l(ifTag)-2); } ret anyChange ? join(tok) : html; }
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1030435 | 
| Snippet name: | html_evaluateIfTags | 
| Eternal ID of this version: | #1030435/7 | 
| Text MD5: | 9b2c8433f51609de62e6a3e238d9c77f | 
| Transpilation MD5: | b397c7bc63e9f5a80dd6454160f6c4ca | 
| Author: | stefan | 
| Category: | javax / html | 
| Type: | JavaX fragment (include) | 
| Public (visible to everyone): | Yes | 
| Archived (hidden from active list): | No | 
| Created/modified: | 2020-12-16 23:39:04 | 
| Source code size: | 878 bytes / 26 lines | 
| Pitched / IR pitched: | No / No | 
| Views / Downloads: | 412 / 549 | 
| Version history: | 6 change(s) | 
| Referenced in: | [show references] |