grub-devel
[Top][All Lists]
Advanced

[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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]