summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-07-12 12:40:28 (GMT)
committer John Mark Bell <jmb@netsurf-browser.org>2009-07-12 12:40:28 (GMT)
commit3980afa794031e82a93c66412e5c6ed07fbc2a78 (patch)
tree41624f1a7eb98c21db78c712af421bdb70e67d60
parentb2fe4fbe5c941e5bccf865536b645725add5e8cf (diff)
downloadlibhubbub-3980afa794031e82a93c66412e5c6ed07fbc2a78.tar.gz
libhubbub-3980afa794031e82a93c66412e5c6ed07fbc2a78.tar.bz2
Fix string comparisons.
svn path=/trunk/hubbub/; revision=8472
-rw-r--r--src/treebuilder/initial.c19
-rw-r--r--src/utils/string.c22
2 files changed, 7 insertions, 34 deletions
diff --git a/src/treebuilder/initial.c b/src/treebuilder/initial.c
index 5f0796c..f26d13f 100644
--- a/src/treebuilder/initial.c
+++ b/src/treebuilder/initial.c
@@ -16,7 +16,7 @@
#include "utils/string.h"
-#define S(s) { s, sizeof s }
+#define S(s) { s, sizeof s - 1 }
struct {
const char *name;
@@ -91,21 +91,10 @@ struct {
static bool starts_with(const uint8_t *a, size_t a_len, const uint8_t *b,
size_t b_len)
{
- uint8_t z1, z2;
- const uint8_t *s1, *s2;
-
if (a_len < b_len)
return false;
- for (s1 = a, s2 = b; b_len > 0; s1++, s2++, b_len--)
- {
- z1 = (*s1 & ~0x20);
- z2 = (*s2 & ~0x20);
- if (z1 != z2) return false;
- if (!z1) return true;
- }
-
- return true;
+ return strncasecmp((const char *) a, (const char *) b, b_len) == 0;
}
@@ -132,7 +121,7 @@ static bool lookup_full_quirks(hubbub_treebuilder *treebuilder,
UNUSED(treebuilder);
-#define S(s) (uint8_t *) s, sizeof s
+#define S(s) (uint8_t *) s, sizeof s - 1
/* Check the name is "HTML" (case-insensitively) */
if (!hubbub_string_match_ci(name, name_len, S("HTML")))
@@ -191,7 +180,7 @@ static bool lookup_limited_quirks(hubbub_treebuilder *treebuilder,
UNUSED(treebuilder);
-#define S(s) (uint8_t *) s, sizeof s
+#define S(s) (uint8_t *) s, sizeof s - 1
if (starts_with(public_id, public_id_len,
S("-//W3C//DTD XHTML 1.0 Frameset//")) ||
diff --git a/src/utils/string.c b/src/utils/string.c
index e35bec6..e216a55 100644
--- a/src/utils/string.c
+++ b/src/utils/string.c
@@ -8,6 +8,7 @@
#include <stddef.h>
#include <inttypes.h>
#include <stdbool.h>
+#include <string.h>
#include "utils/string.h"
@@ -22,17 +23,10 @@
bool hubbub_string_match(const uint8_t *a, size_t a_len,
const uint8_t *b, size_t b_len)
{
- const uint8_t *s1, *s2;
-
if (a_len != b_len)
return false;
- for (s1 = a, s2 = b; b_len > 0; s1++, s2++, b_len--)
- {
- if (*s1 != *s2) return false;
- }
-
- return true;
+ return strncmp((const char *) a, (const char *) b, b_len) == 0;
}
/**
@@ -46,18 +40,8 @@ bool hubbub_string_match(const uint8_t *a, size_t a_len,
bool hubbub_string_match_ci(const uint8_t *a, size_t a_len,
const uint8_t *b, size_t b_len)
{
- uint8_t z1, z2;
- const uint8_t *s1, *s2;
-
if (a_len != b_len)
return false;
- for (s1 = a, s2 = b; b_len > 0; s1++, s2++, b_len--)
- {
- z1 = (*s1 & ~0x20);
- z2 = (*s2 & ~0x20);
- if (z1 != z2) return false;
- }
-
- return true;
+ return strncasecmp((const char *) a, (const char *) b, b_len) == 0;
}