Author: tlsa
Date: Thu Dec 22 08:16:52 2011
New Revision: 13327
URL:
http://source.netsurf-browser.org?rev=13327&view=rev
Log:
Fix comparison of interned and non-interned dom strings. Constify dom string data
accessers.
Modified:
trunk/libdom/examples/dom-structure-dump.c
trunk/libdom/include/dom/core/string.h
trunk/libdom/src/core/string.c
Modified: trunk/libdom/examples/dom-structure-dump.c
URL:
http://source.netsurf-browser.org/trunk/libdom/examples/dom-structure-dum...
==============================================================================
--- trunk/libdom/examples/dom-structure-dump.c (original)
+++ trunk/libdom/examples/dom-structure-dump.c Thu Dec 22 08:16:52 2011
@@ -133,7 +133,8 @@
/**
* 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)
Modified: trunk/libdom/include/dom/core/string.h
URL:
http://source.netsurf-browser.org/trunk/libdom/include/dom/core/string.h?...
==============================================================================
--- trunk/libdom/include/dom/core/string.h (original)
+++ trunk/libdom/include/dom/core/string.h Thu Dec 22 08:16:52 2011
@@ -49,10 +49,10 @@
* @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
Modified: trunk/libdom/src/core/string.c
URL:
http://source.netsurf-browser.org/trunk/libdom/src/core/string.c?rev=1332...
==============================================================================
--- trunk/libdom/src/core/string.c (original)
+++ trunk/libdom/src/core/string.c Thu Dec 22 08:16:52 2011
@@ -214,6 +214,8 @@
*/
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 @@
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 @@
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 @@
* @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 @@
*
* \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;