]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
utf16_to_utf8
authorphcoder <phcoder@debian.easynote.phnet.easynote.phnet>
Fri, 28 Aug 2009 18:58:50 +0000 (20:58 +0200)
committerphcoder <phcoder@debian.easynote.phnet.easynote.phnet>
Fri, 28 Aug 2009 18:58:50 +0000 (20:58 +0200)
fs/fat.c
fs/hfsplus.c
fs/iso9660.c
fs/jfs.c
fs/ntfs.c
include/grub/charset.h [new file with mode: 0644]
include/grub/misc.h
kern/efi/efi.c
kern/misc.c
loader/efi/chainloader.c

index 8440e43fa5b7b142a2a7e8859236f7016adae2ed..e4a072952d8e88343912270de7a6a64ff8e1fd0e 100644 (file)
--- a/fs/fat.c
+++ b/fs/fat.c
@@ -25,6 +25,7 @@
 #include <grub/mm.h>
 #include <grub/err.h>
 #include <grub/dl.h>
+#include <grub/charset.h>
 
 #define GRUB_FAT_DIR_ENTRY_SIZE        32
 
index 5e0ab093f2d3afc933a97e7de0a33df5a9671674..3c2e0c7bdd548c7ae8508bfe26bd70f36dac3a1d 100644 (file)
@@ -28,6 +28,7 @@
 #include <grub/types.h>
 #include <grub/fshelp.h>
 #include <grub/hfs.h>
+#include <grub/charset.h>
 
 #define GRUB_HFSPLUS_MAGIC 0x482B
 #define GRUB_HFSPLUSX_MAGIC 0x4858
index 9b7ce765b32b9e7416029c8e8bc7364873642946..976222a4581b4efccc8eeba56cbeade54695f6fb 100644 (file)
@@ -26,6 +26,7 @@
 #include <grub/dl.h>
 #include <grub/types.h>
 #include <grub/fshelp.h>
+#include <grub/charset.h>
 
 #define GRUB_ISO9660_FSTYPE_DIR                0040000
 #define GRUB_ISO9660_FSTYPE_REG                0100000
index b73f9bdd47065093dd7cca4b3bf5304397fed9f1..589b6ae5ac43c0132f4a2752a45d92b3eafb7612 100644 (file)
--- a/fs/jfs.c
+++ b/fs/jfs.c
@@ -24,6 +24,7 @@
 #include <grub/disk.h>
 #include <grub/dl.h>
 #include <grub/types.h>
+#include <grub/charset.h>
 
 #define GRUB_JFS_MAX_SYMLNK_CNT        8
 #define GRUB_JFS_FILETYPE_MASK 0170000
index 3ff487c6e8460a54b3384dec34d76ef05846bc47..ab75ccc63775da2ad7515916d69385dfb636d31b 100644 (file)
--- a/fs/ntfs.c
+++ b/fs/ntfs.c
@@ -24,6 +24,7 @@
 #include <grub/dl.h>
 #include <grub/fshelp.h>
 #include <grub/ntfs.h>
+#include <grub/charset.h>
 
 static grub_dl_t my_mod;
 
diff --git a/include/grub/charset.h b/include/grub/charset.h
new file mode 100644 (file)
index 0000000..b1db51f
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CHARSET_HEADER
+#define GRUB_CHARSET_HEADER 1
+
+/* Convert UTF-16 to UTF-8.  */
+static inline grub_uint8_t *
+grub_utf16_to_utf8 (grub_uint8_t *dest, grub_uint16_t *src,
+                   grub_size_t size)
+{
+  grub_uint32_t code_high = 0;
+
+  while (size--)
+    {
+      grub_uint32_t code = *src++;
+
+      if (code_high)
+       {
+         if (code >= 0xDC00 && code <= 0xDFFF)
+           {
+             /* Surrogate pair.  */
+             code = ((code_high - 0xD800) << 12) + (code - 0xDC00) + 0x10000;
+
+             *dest++ = (code >> 18) | 0xF0;
+             *dest++ = ((code >> 12) & 0x3F) | 0x80;
+             *dest++ = ((code >> 6) & 0x3F) | 0x80;
+             *dest++ = (code & 0x3F) | 0x80;
+           }
+         else
+           {
+             /* Error...  */
+             *dest++ = '?';
+           }
+
+         code_high = 0;
+       }
+      else
+       {
+         if (code <= 0x007F)
+           *dest++ = code;
+         else if (code <= 0x07FF)
+           {
+             *dest++ = (code >> 6) | 0xC0;
+             *dest++ = (code & 0x3F) | 0x80;
+           }
+         else if (code >= 0xD800 && code <= 0xDBFF)
+           {
+             code_high = code;
+             continue;
+           }
+         else if (code >= 0xDC00 && code <= 0xDFFF)
+           {
+             /* Error... */
+             *dest++ = '?';
+           }
+         else
+           {
+             *dest++ = (code >> 12) | 0xE0;
+             *dest++ = ((code >> 6) & 0x3F) | 0x80;
+             *dest++ = (code & 0x3F) | 0x80;
+           }
+       }
+    }
+
+  return dest;
+}
+
+#endif
index a63a0b4426fe1c6c7901ee1cd5d2f70415c42001..51a4650c8076a601e30a7a4fcf34af2f09c28fc3 100644 (file)
@@ -177,9 +177,6 @@ int EXPORT_FUNC(grub_sprintf) (char *str, const char *fmt, ...) __attribute__ ((
 int EXPORT_FUNC(grub_vsprintf) (char *str, const char *fmt, va_list args);
 void EXPORT_FUNC(grub_exit) (void) __attribute__ ((noreturn));
 void EXPORT_FUNC(grub_abort) (void) __attribute__ ((noreturn));
-grub_uint8_t *EXPORT_FUNC(grub_utf16_to_utf8) (grub_uint8_t *dest,
-                                              grub_uint16_t *src,
-                                              grub_size_t size);
 grub_ssize_t EXPORT_FUNC(grub_utf8_to_ucs4) (grub_uint32_t *dest,
                                             grub_size_t destsize,
                                             const grub_uint8_t *src,
index 8e09a90c0b5e001b7f16a5662efddbcb52606ae3..7be7882a3e065149069c2a91614707d09c90b992 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include <grub/misc.h>
+#include <grub/charset.h>
 #include <grub/efi/api.h>
 #include <grub/efi/efi.h>
 #include <grub/efi/console_control.h>
index 1c38fe661baed462a85d370bdded6f4cf67e4d84..b5e41d1aa0b70e49b4e3942ed21d7a48a78066b0 100644 (file)
@@ -837,68 +837,6 @@ grub_sprintf (char *str, const char *fmt, ...)
   return ret;
 }
 
-/* Convert UTF-16 to UTF-8.  */
-grub_uint8_t *
-grub_utf16_to_utf8 (grub_uint8_t *dest, grub_uint16_t *src,
-                   grub_size_t size)
-{
-  grub_uint32_t code_high = 0;
-
-  while (size--)
-    {
-      grub_uint32_t code = *src++;
-
-      if (code_high)
-       {
-         if (code >= 0xDC00 && code <= 0xDFFF)
-           {
-             /* Surrogate pair.  */
-             code = ((code_high - 0xD800) << 12) + (code - 0xDC00) + 0x10000;
-
-             *dest++ = (code >> 18) | 0xF0;
-             *dest++ = ((code >> 12) & 0x3F) | 0x80;
-             *dest++ = ((code >> 6) & 0x3F) | 0x80;
-             *dest++ = (code & 0x3F) | 0x80;
-           }
-         else
-           {
-             /* Error...  */
-             *dest++ = '?';
-           }
-
-         code_high = 0;
-       }
-      else
-       {
-         if (code <= 0x007F)
-           *dest++ = code;
-         else if (code <= 0x07FF)
-           {
-             *dest++ = (code >> 6) | 0xC0;
-             *dest++ = (code & 0x3F) | 0x80;
-           }
-         else if (code >= 0xD800 && code <= 0xDBFF)
-           {
-             code_high = code;
-             continue;
-           }
-         else if (code >= 0xDC00 && code <= 0xDFFF)
-           {
-             /* Error... */
-             *dest++ = '?';
-           }
-         else
-           {
-             *dest++ = (code >> 12) | 0xE0;
-             *dest++ = ((code >> 6) & 0x3F) | 0x80;
-             *dest++ = (code & 0x3F) | 0x80;
-           }
-       }
-    }
-
-  return dest;
-}
-
 /* Convert a (possibly null-terminated) UTF-8 string of at most SRCSIZE
    bytes (if SRCSIZE is -1, it is ignored) in length to a UCS-4 string.
    Return the number of characters converted. DEST must be able to hold
index 01acc41352a7e2860cc019f3ca56b6eb46b895a6..9c833e9b92f0dee08ceb9522b90373342e9f4b7e 100644 (file)
@@ -25,6 +25,7 @@
 #include <grub/device.h>
 #include <grub/disk.h>
 #include <grub/misc.h>
+#include <grub/charset.h>
 #include <grub/mm.h>
 #include <grub/types.h>
 #include <grub/dl.h>