X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhtml_parser.cpp;h=cb1cda55da2b8143f4cf00eb733959756d417cc8;hb=fe752902775deb62f98786bd18b89a6a0edd0d42;hp=01cf973838eb2be8879dacc4867f78a67c072016;hpb=f51a51c6c6e1f8c5de6e90f548df3d8dc12e00ac;p=metaproxy-moved-to-github.git diff --git a/src/html_parser.cpp b/src/html_parser.cpp index 01cf973..cb1cda5 100644 --- a/src/html_parser.cpp +++ b/src/html_parser.cpp @@ -52,17 +52,6 @@ void mp::HTMLParser::parse(mp::HTMLParserEvent & event, const char *str) const parse_str(event, str); } -//static C functions follow would probably make sense to wrap this in PIMPL? - -static char* dupe(const char *buff, int len) -{ - char *value = (char *) malloc(len + 1); - assert(value); - memcpy(value, buff, len); - value[len] = '\0'; - return value; -} - static int skipSpace(const char *cp) { int i = 0; @@ -75,7 +64,7 @@ static int skipName(const char *cp, char *dst) { int i; int j = 0; - for (i=0; cp[i] && !strchr(SPACECHR "/>=", cp[i]); i++) + for (i = 0; cp[i] && !strchr(SPACECHR "/>=", cp[i]); i++) if (j < TAG_MAX_LEN-1) { dst[j] = tolower(cp[j]); @@ -135,7 +124,7 @@ static int tagAttrs(mp::HTMLParserEvent & event, i += nor; if (nor) { - DEBUG(printf ("------ attr %s=%s\n", attr_name, dupe(attr_value, val_len))); + DEBUG(printf ("------ attr %s=%.*s\n", attr_name, val_len, attr_value)); event.attribute(tagName, attr_name, attr_value, val_len); } else @@ -193,7 +182,8 @@ static void tagText(mp::HTMLParserEvent & event, const char *text_start, const c { if (text_end - text_start) //got text to flush { - DEBUG(printf("------ text %s\n", dupe(text_start, text_end-text_start))); + DEBUG(printf("------ text %.*s\n", + (int) (text_end - text_start), text_start)); event.text(text_start, text_end-text_start); } }