// 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)); S closingTag = "/" + tag; 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)) ++level; else if (eqic(tag2, closingTag)) { --level; ifdef findClosingTag_debug printVars_str("findClosingTag", +level); endifdef if (level == 0) ret i; } } ret l(tok); }