summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/dom-structure-dump.c3
-rw-r--r--include/dom/core/string.h4
-rw-r--r--src/core/string.c22
3 files changed, 17 insertions, 12 deletions
diff --git a/examples/dom-structure-dump.c b/examples/dom-structure-dump.c
index bd73799..91cfda2 100644
--- a/examples/dom-structure-dump.c
+++ b/examples/dom-structure-dump.c
@@ -133,7 +133,8 @@ dom_document *create_doc_dom_from_file(char *file)
/**
* Dump attribute/value for an element node
*
- * \param node The element node to dump attribute details for
+ * \param node The element node to dump attribute details for
+ * \param attribute The attribute to dump
* \return true on success, or false on error
*/
bool dump_dom_element_attribute(dom_node_internal *node, char *attribute)
diff --git a/include/dom/core/string.h b/include/dom/core/string.h
index 31ee54c..9d37547 100644
--- a/include/dom/core/string.h
+++ b/include/dom/core/string.h
@@ -49,10 +49,10 @@ uint32_t dom_string_length(dom_string *str);
* @note: This function is just provided for the convenience of accessing the
* raw C string character, no change on the result string is allowed.
*/
-const char *dom_string_data(dom_string *str);
+const char *dom_string_data(const dom_string *str);
/* Get the byte length of this dom_string */
-size_t dom_string_byte_length(dom_string *str);
+size_t dom_string_byte_length(const dom_string *str);
/* Get the UCS-4 character at position index, the index should be in
* [0, length), and length can be get by calling dom_string_length
diff --git a/src/core/string.c b/src/core/string.c
index c5859af..be0053e 100644
--- a/src/core/string.c
+++ b/src/core/string.c
@@ -214,6 +214,8 @@ dom_exception dom_string_intern(dom_string *str,
*/
bool dom_string_isequal(const dom_string *s1, const dom_string *s2)
{
+ size_t len;
+
if (s1 == NULL)
s1 = &empty_string;
@@ -229,11 +231,12 @@ bool dom_string_isequal(const dom_string *s1, const dom_string *s2)
return match;
}
- if (s1->data.cdata.len != s2->data.cdata.len)
+ len = dom_string_byte_length(s1);
+
+ if (len != dom_string_byte_length(s2))
return false;
- return 0 == memcmp(s1->data.cdata.ptr, s2->data.cdata.ptr,
- s1->data.cdata.len);
+ return 0 == memcmp(dom_string_data(s1), dom_string_data(s2), len);
}
/**
@@ -275,12 +278,13 @@ bool dom_string_caseless_isequal(const dom_string *s1, const dom_string *s2)
return match;
}
- if (s1->data.cdata.len != s2->data.cdata.len)
+ len = dom_string_byte_length(s1);
+
+ if (len != dom_string_byte_length(s2))
return false;
- d1 = s1->data.cdata.ptr;
- d2 = s2->data.cdata.ptr;
- len = s1->data.cdata.len;
+ d1 = (const uint8_t *) dom_string_data(s1);
+ d2 = (const uint8_t *) dom_string_data(s2);
while (len > 0) {
if (dolower(*d1) != dolower(*d2))
@@ -787,7 +791,7 @@ dom_exception _dom_exception_from_lwc_error(lwc_error err)
* @note: This function is just provided for the convenience of accessing the
* raw C string character, no change on the result string is allowed.
*/
-const char *dom_string_data(dom_string *str)
+const char *dom_string_data(const dom_string *str)
{
if (str->type == DOM_STRING_CDATA) {
return (const char *) str->data.cdata.ptr;
@@ -800,7 +804,7 @@ const char *dom_string_data(dom_string *str)
*
* \param str The dom_string object
*/
-size_t dom_string_byte_length(dom_string *str)
+size_t dom_string_byte_length(const dom_string *str)
{
if (str->type == DOM_STRING_CDATA) {
return str->data.cdata.len;