summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog15
-rw-r--r--docs/examples/selection-example-1.c2
-rw-r--r--docs/examples/selection-example-1.css4
-rw-r--r--docs/examples/selection-example-1.xml4
-rw-r--r--src/seleng/cr-sel-eng.c75
-rw-r--r--tests/test-inputs/test5.1.css1
-rw-r--r--tests/test5-main.c13
7 files changed, 88 insertions, 26 deletions
diff --git a/ChangeLog b/ChangeLog
index db41a3a..4124e92 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2003-12-14 Dodji Seketeli <dodji@gnome.org>
+
+ * docs/examples/selection-example-1.c:
+ * docs/examples/selection-example-1.xml:
+ * docs/examples/selection-example-1.css: added a test case
+ for the A + B type of selectors.
+ added
+ * src/seleng/cr-sel-eng.c:
+ (get_next_element_node)
+ (get_prev_element_node)
+ (get_next_parent_element_node): added these helper functions
+ to help ignore non element nodes in the selector matcher.
+ (sel_matches_node_real): Do not consider non element nodes
+ when evaluating a selector.
+
2003-12-13 Dodji Seketeli <dodji@gnome.org>
============= 0.4 release ================
* README: updated this.
diff --git a/docs/examples/selection-example-1.c b/docs/examples/selection-example-1.c
index ab94492..4932a86 100644
--- a/docs/examples/selection-example-1.c
+++ b/docs/examples/selection-example-1.c
@@ -5,7 +5,7 @@
*
* To compile it using gcc, type
*
- * gcc `croco-config --cflags` `croco-config --libs` -o selection-example-1 selection-example-1.c
+ * gcc -g `croco-config --cflags` `croco-config --libs` -o selection-example-1 selection-example-1.c
*
* @author Stefan Seefeld <seefeld@sympatico.ca>
*/
diff --git a/docs/examples/selection-example-1.css b/docs/examples/selection-example-1.css
index a50fdb4..044e053 100644
--- a/docs/examples/selection-example-1.css
+++ b/docs/examples/selection-example-1.css
@@ -35,3 +35,7 @@ entry[type=notice] note[id=bar]
{
padding : 5px;
}
+
+note + notea {
+ color: notea-color ;
+}
diff --git a/docs/examples/selection-example-1.xml b/docs/examples/selection-example-1.xml
index 90724d3..4c3f558 100644
--- a/docs/examples/selection-example-1.xml
+++ b/docs/examples/selection-example-1.xml
@@ -2,11 +2,13 @@
<report>
<entry type="notice">
<note id="foo"/>
+ <notea/>
<note id="bar"/>
</entry>
<entry>
+ <notea/>
<note/>
<note id="foo"/>
<note id="bar"/>
</entry>
-</report> \ No newline at end of file
+</report>
diff --git a/src/seleng/cr-sel-eng.c b/src/seleng/cr-sel-eng.c
index 9711955..3070aa6 100644
--- a/src/seleng/cr-sel-eng.c
+++ b/src/seleng/cr-sel-eng.c
@@ -389,6 +389,52 @@ additional_selector_matches_node (CRAdditionalSel *a_add_sel,
return FALSE ;
}
+static xmlNode *
+get_next_element_node (xmlNode *a_node)
+{
+ xmlNode *cur_node = NULL ;
+
+ g_return_val_if_fail (a_node, NULL) ;
+
+ cur_node = a_node->next ;
+ while (cur_node && cur_node->type != XML_ELEMENT_NODE)
+ {
+ cur_node = cur_node->next ;
+ }
+ return cur_node ;
+}
+
+
+static xmlNode *
+get_prev_element_node (xmlNode *a_node)
+{
+ xmlNode *cur_node = NULL ;
+
+ g_return_val_if_fail (a_node, NULL) ;
+
+ cur_node = a_node->prev ;
+ while (cur_node && cur_node->type != XML_ELEMENT_NODE)
+ {
+ cur_node = cur_node->prev ;
+ }
+ return cur_node ;
+}
+
+static xmlNode *
+get_next_parent_element_node (xmlNode *a_node)
+{
+ xmlNode *cur_node = NULL ;
+
+ g_return_val_if_fail (a_node, NULL) ;
+
+ cur_node = a_node->parent ;
+ while (cur_node && cur_node->type != XML_ELEMENT_NODE)
+ {
+ cur_node = cur_node->parent ;
+ }
+ return cur_node ;
+}
+
/**
*Evaluate a selector (a simple selectors list) and says
*if it matches the xml node given in parameter.
@@ -467,7 +513,7 @@ sel_matches_node_real (CRSelEng *a_this, CRSimpleSel *a_sel,
}
} else {
goto walk_a_step_in_expr ;
- }
+ }
}
goto done ;
}
@@ -487,7 +533,7 @@ sel_matches_node_real (CRSelEng *a_this, CRSimpleSel *a_sel,
} else {
goto done ;
}
-
+
walk_a_step_in_expr:
if (a_recurse == FALSE)
{
@@ -521,14 +567,11 @@ sel_matches_node_real (CRSelEng *a_this, CRSimpleSel *a_sel,
for (n = cur_node->parent ; n ; n = n->parent)
{
status =
- sel_matches_node_real (a_this,
- cur_sel->prev,
- n,
- &matches,
- FALSE) ;
+ sel_matches_node_real
+ (a_this, cur_sel->prev,
+ n, &matches, FALSE) ;
if (status != CR_OK)
goto done ;
-
if (matches == TRUE)
{
cur_node = n ;
@@ -554,28 +597,26 @@ sel_matches_node_real (CRSelEng *a_this, CRSimpleSel *a_sel,
*/
break ;
}
-
+
case COMB_PLUS:
- {
- if (!cur_node->prev)
+ cur_node = get_prev_element_node (cur_node);
+ if (!cur_node)
goto done ;
- cur_node = cur_node->prev ;
- }
break ;
case COMB_GT:
- if (!cur_node->parent)
+ cur_node = get_next_parent_element_node
+ (cur_node) ;
+ if (!cur_node)
goto done ;
- cur_node = cur_node->parent ;
break ;
default:
goto done ;
}
continue ;
-
}
-
+
/*
*if we reached this point, it means the selector matches
*the xml node.
diff --git a/tests/test-inputs/test5.1.css b/tests/test-inputs/test5.1.css
index e6468fd..e5f2009 100644
--- a/tests/test-inputs/test5.1.css
+++ b/tests/test-inputs/test5.1.css
@@ -9,3 +9,4 @@ E0+E1{pro1:val1}
E1 E1-1 {prop2: val2}
E1 > E1-1 {prop3: val3}
document E1-1 {prop4: val4}
+
diff --git a/tests/test5-main.c b/tests/test5-main.c
index 1912027..6305543 100644
--- a/tests/test5-main.c
+++ b/tests/test5-main.c
@@ -38,7 +38,7 @@ CRDocHandler * gv_test_handler = {0} ;
const guchar *xml_content=
"<document>"
-"<E0>text0</E0>"
+"<E0>text0</E0> "
"<E1><E1-1>text1</E1-1></E1>"
"<E2 attr2=\"val2\">text2</E2>"
"<E3 attr3=\"val3_1 val3_2 val3_3\">text3</E3>"
@@ -133,14 +133,13 @@ walk_xml_tree_and_lookup_rules (CRSelEng *a_sel_eng,
g_print ("\n\nxml end element: %s\n",
cur_node->name);
g_print ("'''''''''''''''''''''''''\n") ;
-
- if (stmts_tab)
- {
- g_free (stmts_tab) ;
- stmts_tab= NULL ;
- }
}
+ if (stmts_tab)
+ {
+ g_free (stmts_tab) ;
+ stmts_tab= NULL ;
+ }
if (cur_node->children)
{
walk_xml_tree_and_lookup_rules