aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2024-02-05 21:39:44 -0600
committerDenis Kenzior <denkenz@gmail.com>2024-02-05 22:02:03 -0600
commitd8a703340f1ea32a65af44fb1407acf55523628c (patch)
tree34ba4cc2b78a2a00dde832fd2e5f4b003f1f70d5
parente71edfe4f476c0e707f6fe1a197ff168436958cb (diff)
utf8: Add l_ascii_strdown
-rw-r--r--ell/ell.sym1
-rw-r--r--ell/utf8.c33
-rw-r--r--ell/utf8.h2
3 files changed, 36 insertions, 0 deletions
diff --git a/ell/ell.sym b/ell/ell.sym
index 6ef885dd..a7fdbb90 100644
--- a/ell/ell.sym
+++ b/ell/ell.sym
@@ -49,6 +49,7 @@ global:
l_strv_eq;
/* utf8 */
l_ascii_table;
+ l_ascii_strdown;
l_utf8_get_codepoint;
l_utf8_validate;
l_utf8_strlen;
diff --git a/ell/utf8.c b/ell/utf8.c
index 015a3c98..4f33f557 100644
--- a/ell/utf8.c
+++ b/ell/utf8.c
@@ -1,6 +1,7 @@
/*
* Embedded Linux library
* Copyright (C) 2011-2014 Intel Corporation
+ * Copyright (C) 2024 Cruise, LLC
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
@@ -42,6 +43,38 @@ LIB_EXPORT unsigned char l_ascii_table[256] = {
[0x80 ... 0xFF] = 0,
};
+/**
+ * l_ascii_strdown
+ * @str: a pointer to an ASCII string
+ * @len: maximum bytes to process or negative if string is null terminated
+ *
+ * Returns: Newly allocated string with all upper case characters converted
+ * to lower case.
+ **/
+LIB_EXPORT char *l_ascii_strdown(const char *str, ssize_t len)
+{
+ size_t slen;
+ size_t i;
+ char *ret;
+
+ if (!str)
+ return NULL;
+
+ if (len < 0)
+ slen = strlen(str);
+ else
+ slen = minsize(strlen(str), (size_t) len);
+
+ ret = l_malloc(slen + 1);
+
+ for (i = 0; i < slen; i++)
+ ret[i] = l_ascii_tolower(str[i]);
+
+ ret[i] = '\0';
+
+ return ret;
+}
+
static inline bool __attribute__ ((always_inline))
valid_unicode(wchar_t c)
{
diff --git a/ell/utf8.h b/ell/utf8.h
index 7817cf16..092e70f6 100644
--- a/ell/utf8.h
+++ b/ell/utf8.h
@@ -103,6 +103,8 @@ static inline __attribute__ ((always_inline)) char l_ascii_tolower(char c)
return c + 32;
}
+char *l_ascii_strdown(const char *str, ssize_t len);
+
bool l_utf8_validate(const char *src, size_t len, const char **end);
size_t l_utf8_strlen(const char *str);