diff options
author | Chris Young <chris@unsatisfactorysoftware.co.uk> | 2012-07-22 11:47:43 +0100 |
---|---|---|
committer | Chris Young <chris@unsatisfactorysoftware.co.uk> | 2012-07-22 11:47:43 +0100 |
commit | 7ca9105673b0360b62a1c144db0fe90aa5b9164f (patch) | |
tree | b1ae865d9e69e1cc7ca8d453a0669e547709d28e /src/core | |
parent | 1f4cf0d70ae1f082c3bf7f08fabc70a40dd0848a (diff) | |
parent | 5b82e5a23e4b442bc330783091ed01b95f037175 (diff) | |
download | libdom-7ca9105673b0360b62a1c144db0fe90aa5b9164f.tar.gz libdom-7ca9105673b0360b62a1c144db0fe90aa5b9164f.tar.bz2 |
Merge branch 'master' of git://git.netsurf-browser.org/libdom into chris/amiga-hubbub-lib-compat
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/document.c | 3 | ||||
-rw-r--r-- | src/core/node.c | 2 | ||||
-rw-r--r-- | src/core/string.c | 116 |
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; +} + |