diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2016-01-30 11:50:24 +0000 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2016-01-30 12:17:21 +0000 |
commit | 43b2081b8d5e23c8582e2729f18ccd7555be8a40 (patch) | |
tree | 6c08f1930b7045606ee3138aa3c664d4d8eff99c | |
parent | 86508f207b5fbb26db06dd9411d08bb0b9bfa6c8 (diff) | |
download | libwapcaplet-43b2081b8d5e23c8582e2729f18ccd7555be8a40.tar.gz libwapcaplet-43b2081b8d5e23c8582e2729f18ccd7555be8a40.tar.bz2 |
Add lwc_string_tolower() API.
-rw-r--r-- | include/libwapcaplet/libwapcaplet.h | 10 | ||||
-rw-r--r-- | src/libwapcaplet.c | 19 |
2 files changed, 29 insertions, 0 deletions
diff --git a/include/libwapcaplet/libwapcaplet.h b/include/libwapcaplet/libwapcaplet.h index 4c0fc71..c0e8c29 100644 --- a/include/libwapcaplet/libwapcaplet.h +++ b/include/libwapcaplet/libwapcaplet.h @@ -106,6 +106,16 @@ extern lwc_error lwc_intern_substring(lwc_string *str, lwc_string **ret); /** + * Optain a lowercased lwc_string from given lwc_string. + * + * @param str String to create lowercase string from. + * @param ret Pointer to ::lwc_string pointer to fill out. + * @return Result of operation, if not OK then the value pointed + * to by \a ret will not be valid. + */ +extern lwc_error lwc_string_tolower(lwc_string *str, lwc_string **ret); + +/** * Increment the reference count on an lwc_string. * * This increases the reference count on the given string. You should diff --git a/src/libwapcaplet.c b/src/libwapcaplet.c index 9360f23..9521e96 100644 --- a/src/libwapcaplet.c +++ b/src/libwapcaplet.c @@ -164,6 +164,25 @@ lwc_intern_substring(lwc_string *str, return lwc_intern_string(CSTR_OF(str) + ssoffset, sslen, ret); } +lwc_error +lwc_string_tolower(lwc_string *str, lwc_string **ret) +{ + assert(str); + assert(ret); + + /* Internally make use of knowledge that insensitive strings + * are lower case. */ + if (str->insensitive == NULL) { + lwc_error error = lwc__intern_caseless_string(str); + if (error != lwc_error_ok) { + return error; + } + } + + *ret = lwc_string_ref(str->insensitive); + return lwc_error_ok; +} + void lwc_string_destroy(lwc_string *str) { |