Enable UTF8 in gnulib regexp.
* config.h.in (RE_ENABLE_I18N) [!GRUB_UTIL]: New define. * grub-core/lib/posix_wrap/ctype.h (islower): Use grub_islower. (isupper): Use grub_isupper. (isascii): New inline function. * grub-core/lib/posix_wrap/wchar.h: Replace dummy with real contents. * grub-core/lib/posix_wrap/wctype.h: Likewise. * grub-core/normal/charset.c (grub_utf8_process): New function. (grub_utf8_to_utf16): Use grub_utf8_process. (grub_encode_utf8_character): New function. (grub_ucs4_to_utf8): Use grub_encode_utf8_character. * include/grub/charset.h (grub_utf8_process): New declaration. (grub_encode_utf8_character): Likewise. * include/grub/misc.h (grub_islower): New inline function. (grub_isupper): Likewise. (grub_strchrsub): Moved down to fix the definitions.
This commit is contained in:
parent
0af2346fdb
commit
c5fc563aff
8 changed files with 380 additions and 106 deletions
|
@ -19,7 +19,92 @@
|
|||
#ifndef GRUB_POSIX_WCHAR_H
|
||||
#define GRUB_POSIX_WCHAR_H 1
|
||||
|
||||
#include <grub/charset.h>
|
||||
|
||||
/* UCS-4. */
|
||||
typedef grub_uint32_t wchar_t;
|
||||
typedef grub_int32_t wint_t;
|
||||
enum
|
||||
{
|
||||
WEOF = -1
|
||||
};
|
||||
|
||||
#define MB_LEN_MAX 4
|
||||
|
||||
/* UCS-4. */
|
||||
typedef grub_int32_t wchar_t;
|
||||
|
||||
typedef struct mbstate {
|
||||
grub_uint32_t code;
|
||||
int count;
|
||||
} mbstate_t;
|
||||
|
||||
static inline size_t
|
||||
mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
|
||||
{
|
||||
const char *ptr;
|
||||
if (!s)
|
||||
{
|
||||
pwc = 0;
|
||||
s = "";
|
||||
n = 1;
|
||||
}
|
||||
|
||||
for (ptr = s; ptr < s + n; ptr++)
|
||||
{
|
||||
if (!grub_utf8_process (*ptr, &ps->code, &ps->count))
|
||||
return -1;
|
||||
if (ps->count)
|
||||
continue;
|
||||
if (pwc)
|
||||
*pwc = ps->code;
|
||||
if (ps->code == 0)
|
||||
return 0;
|
||||
return ptr - s + 1;
|
||||
}
|
||||
return -2;
|
||||
}
|
||||
|
||||
static inline int
|
||||
mbsinit(const mbstate_t *ps)
|
||||
{
|
||||
return ps->count == 0;
|
||||
}
|
||||
|
||||
static inline size_t
|
||||
wcrtomb (char *s, wchar_t wc, mbstate_t *ps __attribute__ ((unused)))
|
||||
{
|
||||
if (s == 0)
|
||||
return 1;
|
||||
return grub_encode_utf8_character ((grub_uint8_t *) s,
|
||||
(grub_uint8_t *) s + MB_LEN_MAX,
|
||||
wc);
|
||||
}
|
||||
|
||||
static inline wint_t btowc (int c)
|
||||
{
|
||||
if (c & ~0x7f)
|
||||
return WEOF;
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
static inline int
|
||||
wcscoll (const wchar_t *s1, const wchar_t *s2)
|
||||
{
|
||||
while (*s1 && *s2)
|
||||
{
|
||||
if (*s1 != *s2)
|
||||
break;
|
||||
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
if (*s1 < *s2)
|
||||
return -1;
|
||||
if (*s1 > *s2)
|
||||
return +1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue