summaryrefslogtreecommitdiff
path: root/src/core/string.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2007-07-10 21:36:14 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2007-07-10 21:36:14 +0000
commitacfc9fd1b44f7b72ba66705daf34914940509793 (patch)
tree9ed7dfde5664ff05fd47565d3f68c27792604500 /src/core/string.c
parentd39dbc93d93f537962fe998031ade04d7ee6ca6a (diff)
downloadlibdom-acfc9fd1b44f7b72ba66705daf34914940509793.tar.gz
libdom-acfc9fd1b44f7b72ba66705daf34914940509793.tar.bz2
Add NodeList and string comparison API
svn path=/trunk/dom/; revision=3394
Diffstat (limited to 'src/core/string.c')
-rw-r--r--src/core/string.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/core/string.c b/src/core/string.c
index a60fa94..d73ce8d 100644
--- a/src/core/string.c
+++ b/src/core/string.c
@@ -217,3 +217,57 @@ dom_exception dom_string_get_data(struct dom_string *str,
return DOM_NO_ERR;
}
+
+/**
+ * Case sensitively compare two DOM strings
+ *
+ * \param s1 The first string to compare
+ * \param s2 The second string to compare
+ * \return 0 if strings match, non-0 otherwise
+ */
+int dom_string_cmp(struct dom_string *s1, struct dom_string *s2)
+{
+ const uint8_t *d1, *d2;
+ size_t l1, l2;
+ dom_exception err;
+
+ err = dom_string_get_data(s1, &d1, &l1);
+ if (err != DOM_NO_ERR)
+ return 1; /* arbitrary */
+
+ err = dom_string_get_data(s2, &d2, &l2);
+ if (err != DOM_NO_ERR)
+ return 1; /* arbitrary */
+
+ if (l1 != l2)
+ return 1; /* arbitrary */
+
+ return strncmp((const char *) d1, (const char *) d2, l1);
+}
+
+/**
+ * Case insensitively compare two DOM strings
+ *
+ * \param s1 The first string to compare
+ * \param s2 The second string to compare
+ * \return 0 if strings match, non-0 otherwise
+ */
+int dom_string_icmp(struct dom_string *s1, struct dom_string *s2)
+{
+ const uint8_t *d1, *d2;
+ size_t l1, l2;
+ dom_exception err;
+
+ err = dom_string_get_data(s1, &d1, &l1);
+ if (err != DOM_NO_ERR)
+ return 1; /* arbitrary */
+
+ err = dom_string_get_data(s2, &d2, &l2);
+ if (err != DOM_NO_ERR)
+ return 1; /* arbitrary */
+
+ if (l1 != l2)
+ return 1; /* arbitrary */
+
+ return strncasecmp((const char *) d1, (const char *) d2, l1);
+}