[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v5 06/16] include/grub/charset.h: Enhance grub_utf16_to_utf8(
From: |
Vitaly Kuzmichev |
Subject: |
Re: [PATCH v5 06/16] include/grub/charset.h: Enhance grub_utf16_to_utf8() |
Date: |
Wed, 23 Aug 2023 12:10:19 +0000 |
Hi Vladimir,
On Tue, 2023-08-22 at 23:55 +0200, Vladimir 'phcoder' Serbinenko wrote:
>
> >
> >
> > diff --git a/include/grub/charset.h b/include/grub/charset.h
> > index 31a3b52dd..635d6df9e 100644
> > --- a/include/grub/charset.h
> > +++ b/include/grub/charset.h
> > @@ -49,6 +49,13 @@
> > #define GRUB_UTF16_LOWER_SURROGATE(code) \
> > (0xDC00 | (((code) - GRUB_UCS2_LIMIT) & 0x3ff))
> >
> > +typedef enum grub_utf16_type
> > + {
> > + UTF16_CPU = 0,
> > + UTF16_LE = 1,
> > + UTF16_BE = 2,
> > + } grub_utf16_type_t;
> > +
>
> As an alternative UTF16_CPU can be an alias to current UTF16_*E. Also
> this needs GRUB_ prefix.
This would be machine specific alias and would significantly complicate
the code with #if-s. Current solution is simple and easy to read, so
everyone understands that UTF16_CPU means to read 16-bit character as
it is without conversion. Your suggestion would just add some more
lines of code in this particular place with no benefit in other places.
GRUB_ prefix is needed indeed, thank you.
> > /* Process one character from UTF8 sequence.
> > At beginning set *code = 0, *count = 0. Returns 0 on failure
> > and
> > 1 on success. *count holds the number of trailing bytes. */
> > @@ -198,13 +205,18 @@ grub_getend (const char *beg, const char
> > *end)
> > /* Convert UTF-16 to UTF-8. */
> > static inline grub_uint8_t *
> > grub_utf16_to_utf8 (grub_uint8_t *dest, const grub_uint16_t *src,
> > - grub_size_t size)
> > + grub_size_t size, grub_utf16_type_t type)
> > {
> > grub_uint32_t code_high = 0;
> >
> > while (size--)
> > {
> > - grub_uint32_t code = *src++;
> > + grub_uint32_t code = grub_get_unaligned16 (src);
> > + src++;
> > + if (type == UTF16_LE)
> > + code = grub_le_to_cpu16 (code);
> > + else if (type == UTF16_BE)
> > + code = grub_be_to_cpu16 (code);
> >
> > if (code_high)
> > {
> > _______________________________________________
> > Grub-devel mailing list
> > Grub-devel@gnu.org
> > https://lists.gnu.org/mailman/listinfo/grub-devel
- Re: [PATCH v5 04/16] include/grub/misc.h: Fix edge case in grub_uuidcasecmp(), (continued)
- [PATCH v5 05/16] commands/search: Add support to search by partition PARTUUID, Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 10/16] commands/search: Add support to search by partition PARTLABEL, Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 13/16] fs/f2fs: Simplify to use grub_utf16_to_utf8_alloc(), Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 07/16] include/grub/charset.h: Add grub_utf16_{strlen, strnlen}(), Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 06/16] include/grub/charset.h: Enhance grub_utf16_to_utf8(), Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 14/16] fs/fat: Simplify to use grub_utf16_to_utf8_alloc(), Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 08/16] include/grub/charset.h: Add grub_utf16_to_utf8_alloc(), Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 15/16] fs/iso9660: Simplify to use grub_utf16_to_utf8_alloc(), Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 09/16] partmap/gpt: Add grub_gpt_partition_get_label(), Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 16/16] fs/ntfs: Simplify to use grub_utf16_to_utf8_alloc(), Vitaly Kuzmichev, 2023/08/22