// i = index of opening tag // returns index of closing tag + 1 (or -1 if no closing tag found) static int findEndOfContainerTag(L tok, int i) { S tag = getTag(tok.get(i)); int j, level = 1; for (j = i+2; j < tok.size(); j += 2) if (isTag(tok.get(j), tag)) ++level; else if (isTag(tok.get(j), "/" + tag)) { --level; if (level == 0) ret j+1; } ret -1; }