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: Vladimir 'phcoder' Serbinenko
Subject: Re: [PATCH v5 06/16] include/grub/charset.h: Enhance grub_utf16_to_utf8()
Date: Tue, 22 Aug 2023 23:55:06 +0200




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.
 /* 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)
        {
--
2.34.1


_______________________________________________
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]