diff options
author | admin@progandy.co.cc <admin@progandy.co.cc@eced67a3-f377-a0ae-92ae-d6de1850b05a> | 2010-09-16 10:35:38 +0000 |
---|---|---|
committer | admin@progandy.co.cc <admin@progandy.co.cc@eced67a3-f377-a0ae-92ae-d6de1850b05a> | 2010-09-16 10:35:38 +0000 |
commit | 8d7addf680fee1d83f443809d02b587b81ced704 (patch) | |
tree | 6b9be482cee18ac0a4ef53087cbe095cd02987d5 /MirOTR | |
parent | 9ff42f0ce72e234de4ab575cb48ca7fa4a9992c7 (diff) |
- improved parsing of html a-tags
git-svn-id: http://mirotr.googlecode.com/svn/trunk@15 eced67a3-f377-a0ae-92ae-d6de1850b05a
Diffstat (limited to 'MirOTR')
-rw-r--r-- | MirOTR/striphtml.cpp | 19 |
1 files 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);
}
|