// tok must come from htmlTok // returns index of closing tag or l(tok) static int findClosingTag(LS tok, int iOpeningTag) { S tag = getTag(tok.get(iOpeningTag)); ifdef findClosingTag_debug print("findClosingTag: tag=" + tag); endifdef int level = 1; for (int i = iOpeningTag+2; i < l(tok); i += 2) { S t = tok.get(i); S tag2 = getTag(t); ifdef findClosingTag_debug printVars_str("findClosingTag", +tag2, +t); endifdef if (eqic(tag2, tag)) { if (isClosingTag(t)) --level; else ++level; ifdef findClosingTag_debug printVars_str("findClosingTag", +level); endifdef if (level == 0) ret i; } } ret l(tok); }