Libraryless. Click here for Pure Java version (2796L/18K).
1 | // pred receives the params of opening tag as string (e.g. <if $bla> => "$bla") |
2 | sS html_evaluateIfTags(S html, IPred<S> pred) { |
3 | LS tok = htmlTok(html); |
4 | bool anyChange; |
5 | while ping (true) { |
6 | LS ifTag = first(findContainerTag(tok, "if")); |
7 | if (ifTag == null) break; |
8 | set anyChange; |
9 | int iElse = indexOfIC(ifTag, "<else>"); |
10 | bool val = pred.get(htmlTagFullParamString(second(ifTag))); |
11 | if (val) { |
12 | // value is true, drop else branch (if there) |
13 | if (iElse >= 0) |
14 | clearTokens(ifTag, iElse, l(ifTag)-2); |
15 | } else { |
16 | // value is false, drop everything up until <else> (or whole thing) |
17 | clearTokens(ifTag, 2, iElse < 0 ? l(ifTag) - 2 : iElse+1); |
18 | } |
19 | |
20 | // clear opening and closing tag |
21 | clearToken(ifTag, 1); |
22 | clearToken(ifTag, l(ifTag)-2); |
23 | } |
24 | |
25 | ret anyChange ? join(tok) : html; |
26 | } |
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: | 198 / 288 |
Version history: | 6 change(s) |
Referenced in: | [show references] |