diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2007-07-10 21:36:14 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2007-07-10 21:36:14 +0000 |
commit | feed6ef8c3bee2354db4c778dd61ad7e756968e8 (patch) | |
tree | 9ed7dfde5664ff05fd47565d3f68c27792604500 /src/core/string.c | |
parent | 7a9d61b0def3e8cff5b25892fdca5c8cdda4b628 (diff) | |
download | libdom-feed6ef8c3bee2354db4c778dd61ad7e756968e8.tar.gz libdom-feed6ef8c3bee2354db4c778dd61ad7e756968e8.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.c | 54 |
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); +} |