diff options
-rw-r--r-- | include/dom/core/string.h | 5 | ||||
-rw-r--r-- | src/core/string.c | 54 |
2 files changed, 59 insertions, 0 deletions
diff --git a/include/dom/core/string.h b/include/dom/core/string.h index 31d8f42..84db35a 100644 --- a/include/dom/core/string.h +++ b/include/dom/core/string.h @@ -38,6 +38,11 @@ bool dom_string_isequal(const dom_string *s1, const dom_string *s2); /* Case insensitively compare two DOM strings */ bool dom_string_caseless_isequal(const dom_string *s1, const dom_string *s2); +/* Case sensitively compare DOM string and lwc_string */ +bool dom_string_lwc_isequal(const dom_string *s1, lwc_string *s2); +/* Case insensitively compare DOM string and lwc_string */ +bool dom_string_caseless_lwc_isequal(const dom_string *s1, lwc_string *s2); + /* Get the index of the first occurrence of a character in a dom string */ uint32_t dom_string_index(dom_string *str, uint32_t chr); /* Get the index of the last occurrence of a character in a dom string */ diff --git a/src/core/string.c b/src/core/string.c index a9659cb..8405c27 100644 --- a/src/core/string.c +++ b/src/core/string.c @@ -309,6 +309,60 @@ bool dom_string_caseless_isequal(const dom_string *s1, const dom_string *s2) return true; } + +/** + * Case sensitively compare DOM string with lwc_string + * + * \param s1 The first string to compare + * \param s2 The second string to compare + * \return true if strings match, false otherwise + * + * Returns false if either are NULL. + */ +bool dom_string_lwc_isequal(const dom_string *s1, lwc_string *s2) +{ + size_t len; + + if (s1 == NULL || s2 == NULL) + return false; + + if (s1->type == DOM_STRING_INTERNED) { + bool match; + + lwc_string_caseless_isequal(s1->data.intern, s2, &match); + + return match; + } + + /* Handle non-interend case */ + len = dom_string_byte_length(s1); + + if (len != lwc_string_length(s2)) + return false; + + return 0 == memcmp(dom_string_data(s1), lwc_string_data(s2), len); +} + + +/** + * Case insensitively compare DOM string with lwc_string + * + * \param s1 The first string to compare + * \param s2 The second string to compare + * \return true if strings match, false otherwise + */ +bool dom_string_caseless_lwc_isequal(const dom_string *s1, lwc_string *s2) +{ +// size_t len; + + if (s1 == NULL || s2 == NULL) + return false; + + /* TODO: rest of this */ + return false; +} + + /** * Get the index of the first occurrence of a character in a dom string * |