summaryrefslogtreecommitdiff
path: root/dict.c
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2004-11-24 12:39:00 +0000
committerDaniel Veillard <veillard@src.gnome.org>2004-11-24 12:39:00 +0000
commit6bb3e86d2c0421d4b3b078ee27cd949865a0cb3f (patch)
treea1c88a48ccd3ba312a8b48c3ec86910de2f85302 /dict.c
parent8b41817d5858297626217e2a6cc0cc176cbfb211 (diff)
downloadlibxml2-6bb3e86d2c0421d4b3b078ee27cd949865a0cb3f.tar.gz
added xmlDictExists() to the dictionnary interface. applying
* dict.c include/libxml/dict.h: added xmlDictExists() to the dictionnary interface. * xmlreader.c: applying xmlTextReaderHasAttributes fix for namespaces from Rob Richards Daniel
Diffstat (limited to 'dict.c')
-rw-r--r--dict.c96
1 files changed, 95 insertions, 1 deletions
diff --git a/dict.c b/dict.c
index 56c5dfb0..2e0948cc 100644
--- a/dict.c
+++ b/dict.c
@@ -486,7 +486,7 @@ xmlDictFree(xmlDictPtr dict) {
* @name: the name of the userdata
* @len: the length of the name, if -1 it is recomputed
*
- * Add the @name to the hash @dict if not present.
+ * Add the @name to the dictionnary @dict if not present.
*
* Returns the internal copy of the name or NULL in case of internal error
*/
@@ -600,6 +600,100 @@ xmlDictLookup(xmlDictPtr dict, const xmlChar *name, int len) {
}
/**
+ * xmlDictExists:
+ * @dict: the dictionnary
+ * @name: the name of the userdata
+ * @len: the length of the name, if -1 it is recomputed
+ *
+ * Check if the @name exists in the dictionnary @dict.
+ *
+ * Returns the internal copy of the name or NULL if not found.
+ */
+const xmlChar *
+xmlDictExists(xmlDictPtr dict, const xmlChar *name, int len) {
+ unsigned long key, okey, nbi = 0;
+ xmlDictEntryPtr entry;
+ xmlDictEntryPtr insert;
+ const xmlChar *ret;
+
+ if ((dict == NULL) || (name == NULL))
+ return(NULL);
+
+ if (len < 0)
+ len = xmlStrlen(name);
+
+ /*
+ * Check for duplicate and insertion location.
+ */
+ okey = xmlDictComputeKey(name, len);
+ key = okey % dict->size;
+ if (dict->dict[key].valid == 0) {
+ insert = NULL;
+ } else {
+ for (insert = &(dict->dict[key]); insert->next != NULL;
+ insert = insert->next) {
+#ifdef __GNUC__
+ if (insert->len == len) {
+ if (!memcmp(insert->name, name, len))
+ return(insert->name);
+ }
+#else
+ if ((insert->len == len) &&
+ (!xmlStrncmp(insert->name, name, len)))
+ return(insert->name);
+#endif
+ nbi++;
+ }
+#ifdef __GNUC__
+ if (insert->len == len) {
+ if (!memcmp(insert->name, name, len))
+ return(insert->name);
+ }
+#else
+ if ((insert->len == len) &&
+ (!xmlStrncmp(insert->name, name, len)))
+ return(insert->name);
+#endif
+ }
+
+ if (dict->subdict) {
+ key = okey % dict->subdict->size;
+ if (dict->subdict->dict[key].valid != 0) {
+ xmlDictEntryPtr tmp;
+
+ for (tmp = &(dict->subdict->dict[key]); tmp->next != NULL;
+ tmp = tmp->next) {
+#ifdef __GNUC__
+ if (tmp->len == len) {
+ if (!memcmp(tmp->name, name, len))
+ return(tmp->name);
+ }
+#else
+ if ((tmp->len == len) &&
+ (!xmlStrncmp(tmp->name, name, len)))
+ return(tmp->name);
+#endif
+ nbi++;
+ }
+#ifdef __GNUC__
+ if (tmp->len == len) {
+ if (!memcmp(tmp->name, name, len))
+ return(tmp->name);
+ }
+#else
+ if ((tmp->len == len) &&
+ (!xmlStrncmp(tmp->name, name, len)))
+ return(tmp->name);
+#endif
+ }
+ key = okey % dict->size;
+ }
+
+ /* not found */
+ return(NULL);
+}
+
+/**
* xmlDictQLookup:
* @dict: the dictionnary
* @prefix: the prefix