From b5c5303e14041f061843e5c8db1d1ff31d2977a7 Mon Sep 17 00:00:00 2001 From: hiro Date: Thu, 11 Aug 2011 02:54:28 +0000 Subject: libsylph/html.c: minor code cleanup. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@2936 ee746299-78ed-0310-b773-934348b2243d --- libsylph/html.c | 78 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 60 insertions(+), 18 deletions(-) (limited to 'libsylph/html.c') diff --git a/libsylph/html.c b/libsylph/html.c index 7799549a..ab769e4e 100644 --- a/libsylph/html.c +++ b/libsylph/html.c @@ -1,6 +1,6 @@ /* * LibSylph -- E-Mail client library - * Copyright (C) 1999-2010 Hiroyuki Yamamoto + * Copyright (C) 1999-2011 Hiroyuki Yamamoto * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -171,11 +171,20 @@ static HTMLSymbol other_symbol_list[] = { static GHashTable *default_symbol_table; static HTMLState html_read_line (HTMLParser *parser); + static void html_append_char (HTMLParser *parser, gchar ch); static void html_append_str (HTMLParser *parser, const gchar *str, gint len); + +static gchar *html_find_char (HTMLParser *parser, + gchar ch); +static gchar *html_find_str (HTMLParser *parser, + const gchar *str); +static gchar *html_find_str_case (HTMLParser *parser, + const gchar *str); + static HTMLState html_parse_tag (HTMLParser *parser); static void html_parse_special (HTMLParser *parser); static void html_get_parenthesis (HTMLParser *parser, @@ -358,6 +367,42 @@ static void html_append_str(HTMLParser *parser, const gchar *str, gint len) parser->newline = FALSE; } +static gchar *html_find_char(HTMLParser *parser, gchar ch) +{ + gchar *p; + + while ((p = strchr(parser->bufp, ch)) == NULL) { + if (html_read_line(parser) == HTML_EOF) + return NULL; + } + + return p; +} + +static gchar *html_find_str(HTMLParser *parser, const gchar *str) +{ + gchar *p; + + while ((p = strstr(parser->bufp, str)) == NULL) { + if (html_read_line(parser) == HTML_EOF) + return NULL; + } + + return p; +} + +static gchar *html_find_str_case(HTMLParser *parser, const gchar *str) +{ + gchar *p; + + while ((p = strcasestr(parser->bufp, str)) == NULL) { + if (html_read_line(parser) == HTML_EOF) + return NULL; + } + + return p; +} + static HTMLTag *html_get_tag(const gchar *str) { HTMLTag *tag; @@ -614,35 +659,32 @@ static void html_get_parenthesis(HTMLParser *parser, gchar *buf, gint len) /* ignore comment / CSS / script stuff */ if (!strncmp(parser->bufp, "")) == NULL) - if (html_read_line(parser) == HTML_EOF) return; - parser->bufp = p + 3; + if ((p = html_find_str(parser, "-->")) != NULL) + parser->bufp = p + 3; return; } if (!g_ascii_strncasecmp(parser->bufp, "bufp += 6; - while ((p = strcasestr(parser->bufp, "bufp = p + 7; - while ((p = strchr(parser->bufp, '>')) == NULL) - if (html_read_line(parser) == HTML_EOF) return; - parser->bufp = p + 1; + if ((p = html_find_str_case(parser, "bufp = p + 7; + if ((p = html_find_char(parser, '>')) != NULL) + parser->bufp = p + 1; + } return; } if (!g_ascii_strncasecmp(parser->bufp, "bufp += 7; - while ((p = strcasestr(parser->bufp, "bufp = p + 8; - while ((p = strchr(parser->bufp, '>')) == NULL) - if (html_read_line(parser) == HTML_EOF) return; - parser->bufp = p + 1; + if ((p = html_find_str_case(parser, "bufp = p + 8; + if ((p = html_find_char(parser, '>')) != NULL) + parser->bufp = p + 1; + } return; } parser->bufp++; - while ((p = strchr(parser->bufp, '>')) == NULL) - if (html_read_line(parser) == HTML_EOF) return; + if ((p = html_find_char(parser, '>')) == NULL) + return; strncpy2(buf, parser->bufp, MIN(p - parser->bufp + 1, len)); g_strstrip(buf); -- cgit v1.2.3