From 86a0037554b2e3618b3a604982be0e9d7374d165 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sun, 25 Mar 2012 08:26:31 +0000 Subject: Complete dom_string / lwc_string comparison function. svn path=/trunk/libdom/; revision=13652 --- src/core/string.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/core/string.c b/src/core/string.c index 4e6d98c..7255241 100644 --- a/src/core/string.c +++ b/src/core/string.c @@ -331,7 +331,7 @@ bool dom_string_lwc_isequal(const dom_string *s1, lwc_string *s2) if (s1->type == DOM_STRING_INTERNED) { bool match; - lwc_string_caseless_isequal(s1->data.intern, s2, &match); + lwc_string_isequal(s1->data.intern, s2, &match); return match; } @@ -352,16 +352,44 @@ bool dom_string_lwc_isequal(const dom_string *s1, lwc_string *s2) * \param s1 The first string to compare * \param s2 The second string to compare * \return true if strings match, false otherwise + * + * Returns false if either are NULL. */ bool dom_string_caseless_lwc_isequal(const dom_string *s1, lwc_string *s2) { -// size_t len; + size_t len; + const uint8_t *d1 = NULL; + const uint8_t *d2 = NULL; if (s1 == NULL || s2 == NULL) return false; - /* TODO: rest of this */ - return false; + if (s1->type == DOM_STRING_INTERNED) { + bool match; + + lwc_string_caseless_isequal(s1->data.intern, s2, &match); + + return match; + } + + len = dom_string_byte_length(s1); + + if (len != lwc_string_length(s2)) + return false; + + d1 = (const uint8_t *) dom_string_data(s1); + d2 = (const uint8_t *) lwc_string_data(s2); + + while (len > 0) { + if (dolower(*d1) != dolower(*d2)) + return false; + + d1++; + d2++; + len--; + } + + return true; } -- cgit v1.2.3