// pred receives the text of opening tag (e.g. "") sS html_evaluateIfTags(S html, IPred 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, ""); bool val = pred.get(second(ifTag)); if (val) { // value is true, drop else branch (if there) if (iElse >= 0) clearTokens(ifTag, iElse, ifTag-2); } else { // value is false, drop everything up until (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; }