summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/dom/core/string.h2
-rw-r--r--src/core/string.c45
-rw-r--r--src/core/string.h4
3 files changed, 30 insertions, 21 deletions
diff --git a/include/dom/core/string.h b/include/dom/core/string.h
index 9d37547..31d8f42 100644
--- a/include/dom/core/string.h
+++ b/include/dom/core/string.h
@@ -26,6 +26,8 @@ void dom_string_unref(dom_string *str);
/* Create a DOM string from a string of characters */
dom_exception dom_string_create(const uint8_t *ptr, size_t len,
dom_string **str);
+dom_exception dom_string_create_interned(const uint8_t *ptr, size_t len,
+ dom_string **str);
/* Obtain an interned representation of a dom string */
dom_exception dom_string_intern(dom_string *str,
diff --git a/src/core/string.c b/src/core/string.c
index be0053e..a9659cb 100644
--- a/src/core/string.c
+++ b/src/core/string.c
@@ -141,35 +141,46 @@ dom_exception dom_string_create(const uint8_t *ptr, size_t len,
}
/**
- * Create a dom_string from a lwc_string
- *
- * \param str The lwc_string
- * \param ret The new dom_string
+ * Create an interned DOM string from a string of characters
+ *
+ * \param ptr Pointer to string of characters
+ * \param len Length, in bytes, of string of characters
+ * \param str Pointer to location to receive result
* \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion
+ *
+ * The returned string will already be referenced, so there is no need
+ * to explicitly reference it.
+ *
+ * The string of characters passed in will be copied for use by the
+ * returned DOM string.
*/
-dom_exception _dom_string_create_from_lwcstring(lwc_string *str,
- dom_string **ret)
+dom_exception dom_string_create_interned(const uint8_t *ptr, size_t len,
+ dom_string **str)
{
- dom_string *r;
+ dom_string *ret;
- if (str == NULL) {
- *ret = NULL;
- return DOM_NO_ERR;
+ if (ptr == NULL || len == 0) {
+ ptr = (const uint8_t *) "";
+ len = 0;
}
- r = malloc(sizeof(dom_string));
- if (r == NULL)
+ ret = malloc(sizeof(dom_string));
+ if (ret == NULL)
return DOM_NO_MEM_ERR;
- r->data.intern = lwc_string_ref(str);
+ if (lwc_intern_string((const char *) ptr, len,
+ &ret->data.intern) != lwc_error_ok) {
+ free(ret);
+ return DOM_NO_MEM_ERR;
+ }
+
+ ret->refcnt = 1;
- r->refcnt = 1;
+ ret->type = DOM_STRING_INTERNED;
- r->type = DOM_STRING_INTERNED;
+ *str = ret;
- *ret = r;
return DOM_NO_ERR;
-
}
/**
diff --git a/src/core/string.h b/src/core/string.h
index 796a2ea..cbf7d36 100644
--- a/src/core/string.h
+++ b/src/core/string.h
@@ -11,10 +11,6 @@
#include <dom/core/string.h>
-/* Create a DOM string from a lwc_string */
-dom_exception _dom_string_create_from_lwcstring(struct lwc_string_s *str,
- dom_string **ret);
-
/* Map the lwc_error to dom_exception */
dom_exception _dom_exception_from_lwc_error(lwc_error err);