2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A
2N/A#ifndef GRUB_POSIX_WCTYPE_H
2N/A#define GRUB_POSIX_WCTYPE_H 1
2N/A
2N/A#include <grub/misc.h>
2N/A#include <wchar.h>
2N/A
2N/Atypedef enum { GRUB_CTYPE_INVALID,
2N/A GRUB_CTYPE_ALNUM, GRUB_CTYPE_CNTRL, GRUB_CTYPE_LOWER,
2N/A GRUB_CTYPE_SPACE, GRUB_CTYPE_ALPHA, GRUB_CTYPE_DIGIT,
2N/A GRUB_CTYPE_PRINT, GRUB_CTYPE_UPPER, GRUB_CTYPE_BLANK,
2N/A GRUB_CTYPE_GRAPH, GRUB_CTYPE_PUNCT, GRUB_CTYPE_XDIGIT,
2N/A GRUB_CTYPE_MAX} wctype_t;
2N/A
2N/A#define CHARCLASS_NAME_MAX (sizeof ("xdigit") - 1)
2N/A
2N/Astatic inline wctype_t
2N/Awctype (const char *name)
2N/A{
2N/A wctype_t i;
2N/A static const char names[][10] = { "",
2N/A "alnum", "cntrl", "lower",
2N/A "space", "alpha", "digit",
2N/A "print", "upper", "blank",
2N/A "graph", "punct", "xdigit" };
2N/A for (i = GRUB_CTYPE_INVALID; i < GRUB_CTYPE_MAX; i++)
2N/A if (grub_strcmp (names[i], name) == 0)
2N/A return i;
2N/A return GRUB_CTYPE_INVALID;
2N/A}
2N/A
2N/A/* FIXME: take into account international lowercase characters. */
2N/Astatic inline int
2N/Aiswlower (wint_t wc)
2N/A{
2N/A return grub_islower (wc);
2N/A}
2N/A
2N/Astatic inline wint_t
2N/Atowlower (wint_t c)
2N/A{
2N/A return grub_tolower (c);
2N/A}
2N/A
2N/Astatic inline wint_t
2N/Atowupper (wint_t c)
2N/A{
2N/A return grub_toupper (c);
2N/A}
2N/A
2N/Astatic inline int
2N/Aiswalnum (wint_t c)
2N/A{
2N/A return grub_isalpha (c) || grub_isdigit (c);
2N/A}
2N/A
2N/Astatic inline int
2N/Aiswctype (wint_t wc, wctype_t desc)
2N/A{
2N/A switch (desc)
2N/A {
2N/A case GRUB_CTYPE_ALNUM:
2N/A return iswalnum (wc);
2N/A case GRUB_CTYPE_CNTRL:
2N/A return grub_iscntrl (wc);
2N/A case GRUB_CTYPE_LOWER:
2N/A return iswlower (wc);
2N/A case GRUB_CTYPE_SPACE:
2N/A return grub_isspace (wc);
2N/A case GRUB_CTYPE_ALPHA:
2N/A return grub_isalpha (wc);
2N/A case GRUB_CTYPE_DIGIT:
2N/A return grub_isdigit (wc);
2N/A case GRUB_CTYPE_PRINT:
2N/A return grub_isprint (wc);
2N/A case GRUB_CTYPE_UPPER:
2N/A return grub_isupper (wc);
2N/A case GRUB_CTYPE_BLANK:
2N/A return wc == ' ' || wc == '\t';
2N/A case GRUB_CTYPE_GRAPH:
2N/A return grub_isgraph (wc);
2N/A case GRUB_CTYPE_PUNCT:
2N/A return grub_isprint (wc) && !grub_isspace (wc) && !iswalnum (wc);
2N/A case GRUB_CTYPE_XDIGIT:
2N/A return grub_isxdigit (wc);
2N/A default:
2N/A return 0;
2N/A }
2N/A}
2N/A
2N/A#endif