diff options
author | Will Thompson <will.thompson@collabora.co.uk> | 2011-11-18 12:40:47 +0000 |
---|---|---|
committer | Will Thompson <will.thompson@collabora.co.uk> | 2011-11-18 12:46:14 +0000 |
commit | ac6bfbe70f5ac35d0b998854d3d5ae17ee55be78 (patch) | |
tree | eb694ac4cf3dd7ed963b874e48306584a772c801 | |
parent | 79008a4927792ddda8720d70d09948951e1b8423 (diff) |
Add wocky_node_matches{,_q}
This makes it easier to verify that a node has the name and namespace
you expect.
Reviewed-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r-- | wocky/wocky-node.c | 49 | ||||
-rw-r--r-- | wocky/wocky-node.h | 10 |
2 files changed, 59 insertions, 0 deletions
diff --git a/wocky/wocky-node.c b/wocky/wocky-node.c index f676cf5..9d67eef 100644 --- a/wocky/wocky-node.c +++ b/wocky/wocky-node.c @@ -836,6 +836,55 @@ wocky_node_has_ns_q (WockyNode *node, GQuark ns) } /** + * wocky_node_matches_q: + * @node: a #WockyNode + * @name: the expected element name, which may not be %NULL + * @ns: the expected element namespace, which may not be 0 + * + * Checks whether a node has a particular name and namespace. + * + * Returns: %TRUE if @node is named @name, in namespace @ns. + */ +gboolean +wocky_node_matches_q ( + WockyNode *node, + const gchar *name, + GQuark ns) +{ + g_return_val_if_fail (node != NULL, FALSE); + g_return_val_if_fail (name != NULL, FALSE); + g_return_val_if_fail (ns != 0, FALSE); + + if (wocky_strdiff (node->name, name)) + return FALSE; + + return wocky_node_has_ns_q (node, ns); +} + +/** + * wocky_node_matches: + * @node: a #WockyNode + * @name: the expected element name, which may not be %NULL + * @ns: the expected element namespace, which may not be %NULL + * + * Checks whether a node has a particular name and namespace. + * + * Returns: %TRUE if @node is named @name, in namespace @ns. + */ +gboolean +wocky_node_matches ( + WockyNode *node, + const gchar *name, + const gchar *ns) +{ + g_return_val_if_fail (node != NULL, FALSE); + g_return_val_if_fail (name != NULL, FALSE); + g_return_val_if_fail (ns != NULL, FALSE); + + return wocky_node_matches_q (node, name, g_quark_try_string (ns)); +} + +/** * wocky_node_get_language: * @node: a #WockyNode * diff --git a/wocky/wocky-node.h b/wocky/wocky-node.h index 1db65b2..dd8b6d4 100644 --- a/wocky/wocky-node.h +++ b/wocky/wocky-node.h @@ -176,6 +176,16 @@ const gchar *wocky_node_get_ns (WockyNode *node); gboolean wocky_node_has_ns (WockyNode *node, const gchar *ns); gboolean wocky_node_has_ns_q (WockyNode *node, GQuark ns); +/* Matching element name and namespace */ +gboolean wocky_node_matches_q ( + WockyNode *node, + const gchar *name, + GQuark ns); +gboolean wocky_node_matches ( + WockyNode *node, + const gchar *name, + const gchar *ns); + /* Setting/Getting language */ const gchar *wocky_node_get_language (WockyNode *node); void wocky_node_set_language (WockyNode *node, const gchar *lang); |