comparison src/html.c @ 5141:5736055629cb

[gaim-migrate @ 5505] this is better (lets you use an apostrophe without things croaking) committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Wed, 16 Apr 2003 17:33:25 +0000
parents 496ea7c1b77b
children 376349b04123
comparison
equal deleted inserted replaced
5140:8c71c0727a1c 5141:5736055629cb
327 char *src_tag; 327 char *src_tag;
328 char *dest_tag; 328 char *dest_tag;
329 }; 329 };
330 330
331 #define ALLOW_TAG_ALT(x, y) if(!g_ascii_strncasecmp(c, "<" x " ", strlen("<" x " "))) { \ 331 #define ALLOW_TAG_ALT(x, y) if(!g_ascii_strncasecmp(c, "<" x " ", strlen("<" x " "))) { \
332 char *o = strchr(c+1, '<'); \ 332 const char *o = c + 1; \
333 char *p = strchr(c+1, '>'); \ 333 const char *p = NULL, *q = NULL, *r = NULL; \
334 if(p && (!o || p < o)) { \ 334 while(*o) { \
335 if(!q && (*o == '\"' || *o == '\'') ) { \
336 q = o; \
337 } else if(q) { \
338 if(*o == *q) { \
339 q = NULL; \
340 } else if(*c == '\\') { \
341 o++; \
342 } \
343 } else if(*o == '<') { \
344 r = o; \
345 } else if(*o == '>') { \
346 p = o; \
347 break; \
348 } \
349 o++; \
350 } \
351 if(p && !r) { \
335 if(*(p-1) != '/') { \ 352 if(*(p-1) != '/') { \
336 struct gaim_parse_tag *pt = g_new0(struct gaim_parse_tag, 1); \ 353 struct gaim_parse_tag *pt = g_new0(struct gaim_parse_tag, 1); \
337 pt->src_tag = x; \ 354 pt->src_tag = x; \
338 pt->dest_tag = y; \ 355 pt->dest_tag = y; \
339 tags = g_list_prepend(tags, pt); \ 356 tags = g_list_prepend(tags, pt); \
369 386
370 void html_to_xhtml(const char *html, char **xhtml_out, char **plain_out) { 387 void html_to_xhtml(const char *html, char **xhtml_out, char **plain_out) {
371 GString *xhtml = g_string_new(""); 388 GString *xhtml = g_string_new("");
372 GString *plain = g_string_new(""); 389 GString *plain = g_string_new("");
373 GList *tags = NULL, *tag; 390 GList *tags = NULL, *tag;
374 const char *q = NULL, *c = html; 391 const char *c = html;
375 while(*c) { 392 while(*c) {
376 if(!q && (*c == '\"' || *c == '\'')) { 393 if(*c == '<') {
377 q = c;
378 xhtml = g_string_append_c(xhtml, *c);
379 plain = g_string_append_c(plain, *c);
380 c++;
381 } else if(q) {
382 if(*c == *q) {
383 q = NULL;
384 } else if(*c == '\\') {
385 xhtml = g_string_append_c(xhtml, *c);
386 plain = g_string_append_c(plain, *c);
387 c++;
388 }
389 xhtml = g_string_append_c(xhtml, *c);
390 plain = g_string_append_c(plain, *c);
391 c++;
392 } else if(*c == '<') {
393 if(*(c+1) == '/') { /* closing tag */ 394 if(*(c+1) == '/') { /* closing tag */
394 tag = tags; 395 tag = tags;
395 while(tag) { 396 while(tag) {
396 struct gaim_parse_tag *pt = tag->data; 397 struct gaim_parse_tag *pt = tag->data;
397 if(!g_ascii_strncasecmp((c+2), pt->src_tag, strlen(pt->src_tag)) && *(c+strlen(pt->src_tag)+2) == '>') { 398 if(!g_ascii_strncasecmp((c+2), pt->src_tag, strlen(pt->src_tag)) && *(c+strlen(pt->src_tag)+2) == '>') {