From 3980afa794031e82a93c66412e5c6ed07fbc2a78 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 12 Jul 2009 12:40:28 +0000 Subject: Fix string comparisons. svn path=/trunk/hubbub/; revision=8472 --- src/treebuilder/initial.c | 19 ++++--------------- src/utils/string.c | 22 +++------------------- 2 files changed, 7 insertions(+), 34 deletions(-) (limited to 'src') 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 #include #include +#include #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; } -- cgit v1.2.3