void XMLWriter::tagOpen(const char* tag, const char* name, const bool newline) { // TODO STACK GUARD strncpy(tagStack[_idx++], tag, XMLWRITER_MAXTAGSIZE); tagStart(tag); if (name[0] != 0) tagField("name", name); tagEnd(newline, NOSLASH); _indent += _indentStep; }
void mp::HTMLParser::Rep::parse_str(HTMLParserEvent &event, const char *cp) { const char *text_start = cp; while (*cp) { if (*cp++ != '<') continue; if (nest && *cp == '!') { int i; tagText(event, text_start, cp - 1); if (cp[1] == '-' && cp[2] == '-') { for (i = 3; cp[i]; i++) if (cp[i] == '-' && cp[i+1] == '-' && cp[i+2] == '>') { i+= 2; event.openTagStart(cp, i); break; } } else { for (i = 1; cp[i] && cp[i] != '>'; i++) ; event.openTagStart(cp, i); } if (m_verbose) printf("------ dtd %.*s\n", i, cp); i += tagEnd(event, cp, i, cp + i); cp += i; text_start = cp; } else if (nest && *cp == '?') { int i; tagText(event, text_start, cp - 1); for (i = 1; cp[i] && cp[i] != '>'; i++) ; event.openTagStart(cp, i); if (m_verbose) printf("------ pi %.*s\n", i, cp); i += tagEnd(event, cp, i, cp + i); cp += i; text_start = cp; } else if (*cp == '/' && isAlpha(cp[1])) { int i; i = skipName(++cp); if (!nest) { if (i == 6 && !yaz_strncasecmp(cp, "script", i)) { int ws = skipSpace(cp + 6); if (cp[ws + 6] == '>') nest = true; /* really terminated */ } if (!nest) continue; } tagText(event, text_start, cp - 2); event.closeTag(cp, i); if (m_verbose) printf("------ tag close %.*s\n", i, cp); i += tagEnd(event, cp, i, cp + i); cp += i; text_start = cp; } else if (nest && isAlpha(*cp)) { int i, j; tagText(event, text_start, cp - 1); i = skipName(cp); event.openTagStart(cp, i); if (m_verbose) printf("------ tag open %.*s\n", i, cp); j = tagAttrs(event, cp, i, cp + i); j += tagEnd(event, cp, i, cp + i + j); if (i == 6 && !yaz_strncasecmp(cp, "script", i)) nest = false; cp += i + j; text_start = cp; } } tagText(event, text_start, cp); }