charset: Add support for calculating bytes occupied by a u16 string
authorSughosh Ganu <sughosh.ganu@linaro.org>
Wed, 6 May 2020 19:12:41 +0000 (22:12 +0300)
committerHeinrich Schuchardt <xypron.glpk@gmx.de>
Sat, 9 May 2020 07:30:28 +0000 (09:30 +0200)
The current code uses 'u16_strlen(x) + 1) * sizeof(u16)' in various
places to calculate the number of bytes occupied by a u16 string.
Let's introduce a wrapper around this. This wrapper is used on following
patches

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
include/charset.h
lib/charset.c

index fde6bddbc2fba733108f200354dd1e9d63a85af0..c118cbeb9abd648a3c5ef18639e400e4d54adc2d 100644 (file)
@@ -195,6 +195,18 @@ int u16_strncmp(const u16 *s1, const u16 *s2, size_t n);
  */
 size_t u16_strlen(const void *in);
 
+/**
+ * u16_strsize() - count size of u16 string in bytes including the null
+ *                character
+ *
+ * Counts the number of bytes occupied by a u16 string
+ *
+ * @in:                        null terminated u16 string
+ * Return:             bytes in a u16 string
+ *
+ */
+size_t u16_strsize(const void *in);
+
 /**
  * u16_strlen - count non-zero words
  *
index 1c6a7f693de4b20da405b33289285e5f258fc6fb..a28034ee1f1ecf3791d08b15a5f20da7808b15c8 100644 (file)
@@ -379,6 +379,11 @@ size_t u16_strnlen(const u16 *in, size_t count)
        return i;
 }
 
+size_t u16_strsize(const void *in)
+{
+       return (u16_strlen(in) + 1) * sizeof(u16);
+}
+
 u16 *u16_strcpy(u16 *dest, const u16 *src)
 {
        u16 *tmp = dest;