aboutsummaryrefslogtreecommitdiff
path: root/libsylph/html.c
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2011-08-11 02:54:28 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2011-08-11 02:54:28 +0000
commitb5c5303e14041f061843e5c8db1d1ff31d2977a7 (patch)
tree640ba2e7a62aeb92b807c28075c1fc2b09561467 /libsylph/html.c
parent86fbb5bb80043fc0004cefa1d28b45782ce70e9f (diff)
libsylph/html.c: minor code cleanup.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@2936 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'libsylph/html.c')
-rw-r--r--libsylph/html.c78
1 files changed, 60 insertions, 18 deletions
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, "<!--", 4)) {
parser->bufp += 4;
- while ((p = strstr(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, "<style", 6)) {
parser->bufp += 6;
- while ((p = strcasestr(parser->bufp, "</style")) == NULL)
- if (html_read_line(parser) == HTML_EOF) return;
- parser->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, "</style")) != NULL) {
+ parser->bufp = p + 7;
+ if ((p = html_find_char(parser, '>')) != NULL)
+ parser->bufp = p + 1;
+ }
return;
}
if (!g_ascii_strncasecmp(parser->bufp, "<script", 7)) {
parser->bufp += 7;
- while ((p = strcasestr(parser->bufp, "</script")) == NULL)
- if (html_read_line(parser) == HTML_EOF) return;
- parser->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, "</script")) != NULL) {
+ 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);