From 8d7addf680fee1d83f443809d02b587b81ced704 Mon Sep 17 00:00:00 2001 From: "admin@progandy.co.cc" Date: Thu, 16 Sep 2010 10:35:38 +0000 Subject: - improved parsing of html a-tags git-svn-id: http://mirotr.googlecode.com/svn/trunk@15 eced67a3-f377-a0ae-92ae-d6de1850b05a --- MirOTR/striphtml.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/MirOTR/striphtml.cpp b/MirOTR/striphtml.cpp index f4eebaf..3262f6d 100644 --- a/MirOTR/striphtml.cpp +++ b/MirOTR/striphtml.cpp @@ -35,14 +35,14 @@ void starttag_cb (void *cbdata, ekhtml_string_t *tag, ekhtml_attr_t *attrs) { case 3: if (_strnicmp(tag->str, "img", 3) == 0) { ekhtml_attr_t *attr = attrs; - data->buffer.append("IMAGE:( "); + data->buffer.append("IMAGE [ "); while (attr) { if (_strnicmp(attr->name.str, "src", attr->name.len)==0) { data->buffer.append(attr->val.str, attr->val.len); break; } } - data->buffer.append(" )"); + data->buffer.append(" ] "); } break; } @@ -55,11 +55,12 @@ void endtag_cb (void *cbdata, ekhtml_string_t *tag) { switch (*(tag->str)) { case 'a': case 'A': - data->buffer.append(":( "); + if (data->stack.empty()) break; + data->buffer.append(" [ "); data->buffer.append(data->stack.top()); mir_free(data->stack.top()); data->stack.pop(); - data->buffer.append(" ) "); + data->buffer.append(" ] "); break; case 'i': case 'I': @@ -78,6 +79,16 @@ void data_cb (void *cbdata, ekhtml_string_t *text) { STRIPHTML_DATA *data = (STRIPHTML_DATA *)cbdata; char* s = (char*) mir_calloc(text->len+1); decode_html_entities_utf8(s, text->str, text->len); + + if (!data->stack.empty()) { + char *top = data->stack.top(); + if (_stricmp(s, top)==0) { + mir_free(top); + data->stack.pop(); + } + } + + data->buffer.append(s); mir_free(s); } -- cgit v1.2.3