summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/document.c3
-rw-r--r--src/core/node.c2
-rw-r--r--src/core/string.c116
3 files changed, 117 insertions, 4 deletions
diff --git a/src/core/document.c b/src/core/document.c
index c43f0bc..456d906 100644
--- a/src/core/document.c
+++ b/src/core/document.c
@@ -143,7 +143,7 @@ dom_exception _dom_document_initialise(dom_document *doc,
/* Intern the empty string. The use of a space in the constant
* is to prevent the compiler warning about an empty string.
*/
- err = dom_string_create_interned((const uint8_t *) ' ', 0,
+ err = dom_string_create_interned((const uint8_t *) " ", 0,
&doc->_memo_empty);
if (err != DOM_NO_ERR) {
dom_string_unref(doc->class_string);
@@ -184,6 +184,7 @@ bool _dom_document_finalise(dom_document *doc)
dom_string_unref(doc->id_name);
dom_string_unref(doc->class_string);
+ dom_string_unref(doc->_memo_empty);
_dom_document_event_internal_finalise(doc, &doc->dei);
diff --git a/src/core/node.c b/src/core/node.c
index 628c7c6..9ddac0c 100644
--- a/src/core/node.c
+++ b/src/core/node.c
@@ -1666,8 +1666,6 @@ dom_exception _dom_node_get_feature(dom_node_internal *node,
{
bool has;
- UNUSED(node);
-
dom_implementation_has_feature(dom_string_data(feature),
dom_string_data(version), &has);
diff --git a/src/core/string.c b/src/core/string.c
index aa046ad..0cadd77 100644
--- a/src/core/string.c
+++ b/src/core/string.c
@@ -890,7 +890,7 @@ const char *dom_string_data(const dom_string *str)
}
}
-/* Get the byte length of this dom_string
+/** Get the byte length of this dom_string
*
* \param str The dom_string object
*/
@@ -904,3 +904,117 @@ size_t dom_string_byte_length(const dom_string *str)
}
}
+/** Convert the given string to uppercase
+ *
+ * \param source
+ * \param ascii_only Whether to only convert [a-z] to [A-Z]
+ * \param upper Result pointer for uppercase string. Caller owns ref
+ *
+ * \return DOM_NO_ERR on success.
+ *
+ * \note Right now, will return DOM_NOT_SUPPORTED_ERR if ascii_only is false.
+ */
+dom_exception
+dom_string_toupper(dom_string *source, bool ascii_only, dom_string **upper)
+{
+ const uint8_t *orig_s = (const uint8_t *) dom_string_data(source);
+ const size_t nbytes = dom_string_byte_length(source);
+ uint8_t *copy_s;
+ size_t index = 0, clen;
+ parserutils_error err;
+ dom_exception exc;
+
+ if (ascii_only == false)
+ return DOM_NOT_SUPPORTED_ERR;
+
+ copy_s = malloc(nbytes);
+ if (copy_s == NULL)
+ return DOM_NO_MEM_ERR;
+ memcpy(copy_s, orig_s, nbytes);
+
+ while (index < nbytes) {
+ err = parserutils_charset_utf8_char_byte_length(orig_s + index,
+ &clen);
+ if (err != PARSERUTILS_OK) {
+ free(copy_s);
+ /** \todo Find a better exception */
+ return DOM_NO_MEM_ERR;
+ }
+
+ if (clen == 1) {
+ if (orig_s[index] >= 'a' &&
+ orig_s[index] <= 'z')
+ copy_s[index] -= 'a' - 'A';
+ }
+
+ index += clen;
+ }
+
+ if (((dom_string_internal*)source)->type == DOM_STRING_CDATA) {
+ exc = dom_string_create(copy_s, nbytes, upper);
+ } else {
+ exc = dom_string_create_interned(copy_s, nbytes, upper);
+ }
+
+ free(copy_s);
+
+ return exc;
+}
+
+/** Convert the given string to lowercase
+ *
+ * \param source
+ * \param ascii_only Whether to only convert [a-z] to [A-Z]
+ * \param lower Result pointer for lowercase string. Caller owns ref
+ *
+ * \return DOM_NO_ERR on success.
+ *
+ * \note Right now, will return DOM_NOT_SUPPORTED_ERR if ascii_only is false.
+ */
+dom_exception
+dom_string_tolower(dom_string *source, bool ascii_only, dom_string **lower)
+{
+ const uint8_t *orig_s = (const uint8_t *) dom_string_data(source);
+ const size_t nbytes = dom_string_byte_length(source);
+ uint8_t *copy_s;
+ size_t index = 0, clen;
+ parserutils_error err;
+ dom_exception exc;
+
+ if (ascii_only == false)
+ return DOM_NOT_SUPPORTED_ERR;
+
+ copy_s = malloc(nbytes);
+ if (copy_s == NULL)
+ return DOM_NO_MEM_ERR;
+ memcpy(copy_s, orig_s, nbytes);
+
+ while (index < nbytes) {
+ err = parserutils_charset_utf8_char_byte_length(orig_s + index,
+ &clen);
+ if (err != PARSERUTILS_OK) {
+ free(copy_s);
+ /** \todo Find a better exception */
+ return DOM_NO_MEM_ERR;
+ }
+
+ if (clen == 1) {
+ if (orig_s[index] >= 'A' &&
+ orig_s[index] <= 'Z')
+ copy_s[index] += 'a' - 'A';
+ }
+
+ index += clen;
+ }
+
+ if (((dom_string_internal*)source)->type == DOM_STRING_CDATA) {
+ exc = dom_string_create(copy_s, nbytes, lower);
+ } else {
+ exc = dom_string_create_interned(copy_s, nbytes, lower);
+ }
+
+ free(copy_s);
+
+ return exc;
+}
+