xml_GNode* xml_node_grep_child (xml_GNode *node,
GTraverseFlags flags,
const gchar* name)
{
g_return_val_if_fail (node, 0);
g_return_val_if_fail (flags <= G_TRAVERSE_MASK, NULL);
if (! name || ! *name || !node->children) return 0;
if (! strchr ("^(?+|\\*", *name))
return xml_node_find_child (node, flags, name);
___ pcre* regex; const char* errmsg; int erridx; int ovector[33];
if (*name == '*' || *name == '+')
regex = pcre_compile (name+1, 0, &errmsg, &erridx, 0);
else if (*name == '?' || *name == '^')
regex = pcre_compile (name+1, PCRE_ANCHORED, &errmsg, &erridx, 0);
else
regex = pcre_compile (name, PCRE_ANCHORED, &errmsg, &erridx, 0);
if (! regex) return 0;
node = node->children;
while (node)
{
if (0< pcre_exec (regex, 0, node->name, strlen(node->name),
0, PCRE_NOTEMPTY, ovector, 33 ))
{
if (*name == '*' || *name == '+' || ! node->name[ovector[1]])
{
if (G_NODE_IS_LEAF (node))
{
if (flags & G_TRAVERSE_LEAFS)
goto returns;
} |
else
{
if (flags & G_TRAVERSE_NON_LEAFS)
goto returns;
} |
} |
} |
node = node->next;
} |
returns:
pcre_free (regex);
return node;
____;
} |
|