summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-07-17 18:07:42 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2009-07-17 18:07:42 +0000
commit6be9de70b8e6cd9427837cc6cae777356f1950ba (patch)
tree7efc786a7cc1f25662c0d5286444b11b3d948bd2 /src
parent8bccb05e6b8b0870fbbc5bab83c228f11d129caf (diff)
downloadlibcss-6be9de70b8e6cd9427837cc6cae777356f1950ba.tar.gz
libcss-6be9de70b8e6cd9427837cc6cae777356f1950ba.tar.bz2
Fix selector hash some more. It turns out that I'd forgotten how it was meant to work.
svn path=/trunk/libcss/; revision=8607
Diffstat (limited to 'src')
-rw-r--r--src/select/hash.c36
-rw-r--r--src/select/hash.h3
-rw-r--r--src/stylesheet.c3
3 files changed, 37 insertions, 5 deletions
diff --git a/src/select/hash.c b/src/select/hash.c
index 2f33877..5bdd22f 100644
--- a/src/select/hash.c
+++ b/src/select/hash.c
@@ -22,6 +22,8 @@ struct css_selector_hash {
hash_entry *slots;
+ lwc_context *ctx;
+
css_allocator_fn alloc;
void *pw;
};
@@ -34,17 +36,19 @@ static inline uint32_t _hash_name(lwc_string *name);
/**
* Create a hash
*
+ * \param dict Dictionary containing interned strings
* \param alloc Memory (de)allocation function
* \param pw Pointer to client-specific private data
* \param hash Pointer to location to receive result
* \return CSS_OK on success, appropriate error otherwise
*/
-css_error css_selector_hash_create(css_allocator_fn alloc, void *pw,
+css_error css_selector_hash_create(lwc_context *dict,
+ css_allocator_fn alloc, void *pw,
css_selector_hash **hash)
{
css_selector_hash *h;
- if (alloc == NULL || hash == NULL)
+ if (dict == NULL || alloc == NULL || hash == NULL)
return CSS_BADPARM;
h = alloc(0, sizeof(css_selector_hash), pw);
@@ -60,6 +64,7 @@ css_error css_selector_hash_create(css_allocator_fn alloc, void *pw,
memset(h->slots, 0, DEFAULT_SLOTS * sizeof(hash_entry));
h->n_slots = DEFAULT_SLOTS;
+ h->ctx = lwc_context_ref(dict);
h->alloc = alloc;
h->pw = pw;
@@ -91,6 +96,8 @@ css_error css_selector_hash_destroy(css_selector_hash *hash)
}
}
+ lwc_context_unref(hash->ctx);
+
hash->alloc(hash->slots, 0, hash->pw);
hash->alloc(hash, 0, hash->pw);
@@ -240,6 +247,23 @@ css_error css_selector_hash_find(css_selector_hash *hash,
head = &hash->slots[index];
+ if (head->sel != NULL) {
+ /* Search through chain for first match */
+ while (head != NULL) {
+ bool match = false;
+
+ lwc_context_string_caseless_isequal(hash->ctx, name,
+ head->sel->data.name, &match);
+ if (match)
+ break;
+
+ head = head->next;
+ }
+
+ if (head == NULL)
+ head = &empty_slot;
+ }
+
(*matched) = (const css_selector **) head;
return CSS_OK;
@@ -264,8 +288,14 @@ css_error css_selector_hash_iterate(css_selector_hash *hash,
if (hash == NULL || current == NULL || next == NULL)
return CSS_BADPARM;
+ /* Look for the next selector with the same element name */
for (head = head->next; head != NULL; head = head->next) {
- if (head->sel->data.name == (*current)->data.name)
+ bool match = false;
+
+ lwc_context_string_caseless_isequal(hash->ctx,
+ head->sel->data.name,
+ (*current)->data.name, &match);
+ if (match)
break;
}
diff --git a/src/select/hash.h b/src/select/hash.h
index b116021..59c8b76 100644
--- a/src/select/hash.h
+++ b/src/select/hash.h
@@ -18,7 +18,8 @@ struct css_selector;
typedef struct css_selector_hash css_selector_hash;
-css_error css_selector_hash_create(css_allocator_fn alloc, void *pw,
+css_error css_selector_hash_create(lwc_context *dict,
+ css_allocator_fn alloc, void *pw,
css_selector_hash **hash);
css_error css_selector_hash_destroy(css_selector_hash *hash);
diff --git a/src/stylesheet.c b/src/stylesheet.c
index 9a5b9a0..7ec55b2 100644
--- a/src/stylesheet.c
+++ b/src/stylesheet.c
@@ -101,7 +101,8 @@ css_error css_stylesheet_create(css_language_level level,
return error;
}
- error = css_selector_hash_create(alloc, alloc_pw, &sheet->selectors);
+ error = css_selector_hash_create(dict, alloc, alloc_pw,
+ &sheet->selectors);
if (error != CSS_OK) {
css_language_destroy(sheet->parser_frontend);
css_parser_destroy(sheet->parser);