1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-10-23 07:20:10 -04:00

Add get_dom_node_prev() which gets the previous sibling of a DOM node

This commit is contained in:
Jonas Fonseca 2006-01-16 05:10:22 +01:00 committed by Jonas Fonseca
parent 4e6b05394d
commit 768f97c38e
2 changed files with 33 additions and 5 deletions

View File

@ -225,16 +225,15 @@ get_dom_node_map_entry(struct dom_node_list *list, enum dom_node_type type,
return dom_node_list_bsearch(&search, list);
}
int
get_dom_node_list_index(struct dom_node *parent, struct dom_node *node)
static int
get_dom_node_list_pos(struct dom_node_list *list, struct dom_node *node)
{
struct dom_node_list **list = get_dom_node_list(parent, node);
struct dom_node *entry;
int i;
if (!list) return -1;
assert(list);
foreach_dom_node (*list, entry, i) {
foreach_dom_node (list, entry, i) {
if (entry == node)
return i;
}
@ -242,6 +241,32 @@ get_dom_node_list_index(struct dom_node *parent, struct dom_node *node)
return -1;
}
int
get_dom_node_list_index(struct dom_node *parent, struct dom_node *node)
{
struct dom_node_list **list = get_dom_node_list(parent, node);
return list ? get_dom_node_list_pos(*list, node) : -1;
}
struct dom_node *
get_dom_node_prev(struct dom_node *node)
{
struct dom_node_list **list;
int index;
assert(node->parent);
list = get_dom_node_list(node->parent, node);
if (!list) return NULL;
index = get_dom_node_list_pos(*list, node);
if (index > 0)
return (*list)->entries[index - 1];
return NULL;
}
/* Nodes */
struct dom_node *

View File

@ -243,6 +243,9 @@ int get_dom_node_list_index(struct dom_node *parent, struct dom_node *node);
* @list is already sorted properly. */
int get_dom_node_map_index(struct dom_node_list *list, struct dom_node *node);
/* Returns the previous sibling to the node. */
struct dom_node *get_dom_node_prev(struct dom_node *node);
/* Looks up the @node_map for a node matching the requested type and name.
* The @subtype maybe be 0 indication unknown subtype and only name should be
* tested else it will indicate either the element or attribute private