* grub-core/kern/efi/efi.c (grub_efi_get_variable): Add new function.
* include/grub/efi/efi.h: Likewise. * include/grub/efi/api.h: Add guid for EFI-specified variables. * include/grub/charset.h (GRUB_MAX_UTF16_PER_UTF8): New definition. * grub-core/normal/charset.c (grub_utf8_process): Move from here ... * include/grub/charset.h (grub_utf8_process): ... to here. Inline. * grub-core/normal/charset.c (grub_utf8_to_utf16): Move from here ... * include/grub/charset.h (grub_utf8_to_utf16): ... to here. Inline.
This commit is contained in:
parent
e33f8d692f
commit
c598862958
6 changed files with 163 additions and 110 deletions
|
@ -53,107 +53,6 @@
|
|||
#include "widthspec.h"
|
||||
#endif
|
||||
|
||||
int
|
||||
grub_utf8_process (grub_uint8_t c, grub_uint32_t *code, int *count)
|
||||
{
|
||||
if (*count)
|
||||
{
|
||||
if ((c & GRUB_UINT8_2_LEADINGBITS) != GRUB_UINT8_1_LEADINGBIT)
|
||||
{
|
||||
*count = 0;
|
||||
/* invalid */
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
*code <<= 6;
|
||||
*code |= (c & GRUB_UINT8_6_TRAILINGBITS);
|
||||
(*count)--;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((c & GRUB_UINT8_1_LEADINGBIT) == 0)
|
||||
{
|
||||
*code = c;
|
||||
return 1;
|
||||
}
|
||||
if ((c & GRUB_UINT8_3_LEADINGBITS) == GRUB_UINT8_2_LEADINGBITS)
|
||||
{
|
||||
*count = 1;
|
||||
*code = c & GRUB_UINT8_5_TRAILINGBITS;
|
||||
return 1;
|
||||
}
|
||||
if ((c & GRUB_UINT8_4_LEADINGBITS) == GRUB_UINT8_3_LEADINGBITS)
|
||||
{
|
||||
*count = 2;
|
||||
*code = c & GRUB_UINT8_4_TRAILINGBITS;
|
||||
return 1;
|
||||
}
|
||||
if ((c & GRUB_UINT8_5_LEADINGBITS) == GRUB_UINT8_4_LEADINGBITS)
|
||||
{
|
||||
*count = 3;
|
||||
*code = c & GRUB_UINT8_3_TRAILINGBITS;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Convert a (possibly null-terminated) UTF-8 string of at most SRCSIZE
|
||||
bytes (if SRCSIZE is -1, it is ignored) in length to a UTF-16 string.
|
||||
Return the number of characters converted. DEST must be able to hold
|
||||
at least DESTSIZE characters. If an invalid sequence is found, return -1.
|
||||
If SRCEND is not NULL, then *SRCEND is set to the next byte after the
|
||||
last byte used in SRC. */
|
||||
grub_size_t
|
||||
grub_utf8_to_utf16 (grub_uint16_t *dest, grub_size_t destsize,
|
||||
const grub_uint8_t *src, grub_size_t srcsize,
|
||||
const grub_uint8_t **srcend)
|
||||
{
|
||||
grub_uint16_t *p = dest;
|
||||
int count = 0;
|
||||
grub_uint32_t code = 0;
|
||||
|
||||
if (srcend)
|
||||
*srcend = src;
|
||||
|
||||
while (srcsize && destsize)
|
||||
{
|
||||
int was_count = count;
|
||||
if (srcsize != (grub_size_t)-1)
|
||||
srcsize--;
|
||||
if (!grub_utf8_process (*src++, &code, &count))
|
||||
{
|
||||
code = '?';
|
||||
count = 0;
|
||||
/* Character c may be valid, don't eat it. */
|
||||
if (was_count)
|
||||
src--;
|
||||
}
|
||||
if (count != 0)
|
||||
continue;
|
||||
if (code == 0)
|
||||
break;
|
||||
if (destsize < 2 && code >= GRUB_UCS2_LIMIT)
|
||||
break;
|
||||
if (code >= GRUB_UCS2_LIMIT)
|
||||
{
|
||||
*p++ = GRUB_UTF16_UPPER_SURROGATE (code);
|
||||
*p++ = GRUB_UTF16_LOWER_SURROGATE (code);
|
||||
destsize -= 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
*p++ = code;
|
||||
destsize--;
|
||||
}
|
||||
}
|
||||
|
||||
if (srcend)
|
||||
*srcend = src;
|
||||
return p - dest;
|
||||
}
|
||||
|
||||
/* Returns -2 if not enough space, -1 on invalid character. */
|
||||
grub_ssize_t
|
||||
grub_encode_utf8_character (grub_uint8_t *dest, grub_uint8_t *destend,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue