LGTM

Le mar. 22 août 2023, 23:41, Vitaly Kuzmichev <vitaly.kuzmic...@rtsoft.de>
a écrit :

> Add two functions to calculate UTF-16 string length. The address to
> UTF-16 string could be unaligned, so use grub_get_unaligned16() to
> iterate over characters.
>
> Signed-off-by: Vitaly Kuzmichev <vitaly.kuzmic...@rtsoft.de>
> ---
>  include/grub/charset.h | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
>
> diff --git a/include/grub/charset.h b/include/grub/charset.h
> index 635d6df9e..099f23fbe 100644
> --- a/include/grub/charset.h
> +++ b/include/grub/charset.h
> @@ -278,6 +278,32 @@ grub_utf16_to_utf8 (grub_uint8_t *dest, const
> grub_uint16_t *src,
>    return dest;
>  }
>
> +/* Returns the length of the UTF16 string, excluding \0.  */
> +static inline grub_size_t
> +grub_utf16_strlen (const void *s)
> +{
> +  const grub_uint8_t *p = s;
> +  grub_size_t len = 0;
> +
> +  while (grub_get_unaligned16 (p + 2 * len))
> +    len++;
> +
> +  return len;
> +}
> +
> +/* Returns the length of the UTF16 string of the fixed size, excluding
> \0.  */
> +static inline grub_size_t
> +grub_utf16_strnlen (const void *s, grub_size_t maxlen)
> +{
> +  const grub_uint8_t *p = s;
> +  grub_size_t len = 0;
> +
> +  while (grub_get_unaligned16 (p + 2 * len) && len < maxlen)
> +    len++;
> +
> +  return len;
> +}
> +
>  #define GRUB_MAX_UTF8_PER_LATIN1 2
>
>  /* Convert Latin1 to UTF-8.  */
> --
> 2.34.1
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to