mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Add wctype(3).
This commit is contained in:
parent
05219a27f2
commit
b9d633108d
6 changed files with 144 additions and 19 deletions
|
@ -117,6 +117,7 @@ vfscanf.o \
|
|||
vsscanf.o \
|
||||
wcrtomb.o \
|
||||
wctomb.o \
|
||||
wctype.o \
|
||||
|
||||
HOSTEDOBJS=\
|
||||
access.o \
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef _WCTYPE_T_DECL
|
||||
#define _WCTYPE_T_DECL
|
||||
typedef __wctype_t wctype_t;
|
||||
typedef int (*wctype_t)(wint_t);
|
||||
#endif
|
||||
|
|
|
@ -31,46 +31,48 @@ __BEGIN_DECLS
|
|||
|
||||
@include(wint_t.h)
|
||||
@include(wctrans_t.h)
|
||||
@include(wctype_t.h)
|
||||
@include(locale_t.h)
|
||||
@include(WEOF.h)
|
||||
|
||||
int iswalnum(wint_t);
|
||||
int iswalpha(wint_t);
|
||||
int iswblank(wint_t);
|
||||
int iswcntrl(wint_t);
|
||||
int iswctype(wint_t, wctype_t);
|
||||
int iswdigit(wint_t);
|
||||
int iswgraph(wint_t);
|
||||
int iswlower(wint_t);
|
||||
int iswprint(wint_t);
|
||||
int iswpunct(wint_t);
|
||||
int iswspace(wint_t);
|
||||
int iswupper(wint_t);
|
||||
int iswxdigit(wint_t);
|
||||
wint_t towlower(wint_t);
|
||||
wint_t towupper(wint_t);
|
||||
wctype_t wctype(const char *);
|
||||
|
||||
/* TODO: These are not implemented in sortix libc yet. */
|
||||
#if defined(__SORTIX_SHOW_UNIMPLEMENTED)
|
||||
int iswalnum(wint_t);
|
||||
int iswalnum_l(wint_t, locale_t);
|
||||
int iswalpha(wint_t);
|
||||
int iswalpha_l(wint_t, locale_t);
|
||||
int iswblank(wint_t);
|
||||
int iswblank_l(wint_t, locale_t);
|
||||
int iswcntrl(wint_t);
|
||||
int iswcntrl_l(wint_t, locale_t);
|
||||
int iswctype(wint_t, wctype_t);
|
||||
int iswctype_l(wint_t, wctype_t, locale_t);
|
||||
int iswdigit(wint_t);
|
||||
int iswdigit_l(wint_t, locale_t);
|
||||
int iswgraph(wint_t);
|
||||
int iswgraph_l(wint_t, locale_t);
|
||||
int iswlower(wint_t);
|
||||
int iswlower_l(wint_t, locale_t);
|
||||
int iswprint(wint_t);
|
||||
int iswprint_l(wint_t, locale_t);
|
||||
int iswpunct(wint_t);
|
||||
int iswpunct_l(wint_t, locale_t);
|
||||
int iswspace(wint_t);
|
||||
int iswspace_l(wint_t, locale_t);
|
||||
int iswupper(wint_t);
|
||||
int iswupper_l(wint_t, locale_t);
|
||||
int iswxdigit(wint_t);
|
||||
int iswxdigit_l(wint_t, locale_t);
|
||||
wint_t towctrans(wint_t, wctrans_t);
|
||||
wint_t towctrans_l(wint_t, wctrans_t, locale_t);
|
||||
wint_t towlower(wint_t);
|
||||
wint_t towlower_l(wint_t, locale_t);
|
||||
wint_t towupper(wint_t);
|
||||
wint_t towupper_l(wint_t, locale_t);
|
||||
wctrans_t wctrans(const char *);
|
||||
wctrans_t wctrans_l(const char *, locale_t);
|
||||
wctype_t wctype(const char *);
|
||||
wctype_t wctype_l(const char *, locale_t);
|
||||
#endif
|
||||
|
||||
|
|
124
libc/wctype.cpp
Normal file
124
libc/wctype.cpp
Normal file
|
@ -0,0 +1,124 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
The Sortix C Library is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The Sortix C Library 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 Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
|
||||
wctype.cpp
|
||||
Character types.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <wctype.h>
|
||||
|
||||
// TODO: Support other locales than ASCII.
|
||||
|
||||
extern "C" int iswalnum(wint_t c)
|
||||
{
|
||||
return iswalpha(c) || iswdigit(c);
|
||||
}
|
||||
|
||||
extern "C" int iswalpha(wint_t c)
|
||||
{
|
||||
return iswupper(c) || iswlower(c);
|
||||
}
|
||||
|
||||
extern "C" int iswblank(wint_t c)
|
||||
{
|
||||
return c == L' ' || c == L'\t';
|
||||
}
|
||||
|
||||
extern "C" int iswcntrl(wint_t c)
|
||||
{
|
||||
return 0 <= c && c < 32;
|
||||
}
|
||||
|
||||
extern "C" int iswdigit(wint_t c)
|
||||
{
|
||||
return L'0' <= c && c <= L'9';
|
||||
}
|
||||
|
||||
extern "C" int iswgraph(wint_t c)
|
||||
{
|
||||
return L'!' <= c && c <= L'~';
|
||||
}
|
||||
|
||||
extern "C" int iswlower(wint_t c)
|
||||
{
|
||||
return L'a' <= c && c <= L'z';
|
||||
}
|
||||
|
||||
extern "C" int iswprint(wint_t c)
|
||||
{
|
||||
return iswgraph(c) || c == L' ';
|
||||
}
|
||||
|
||||
extern "C" int iswpunct(wint_t c)
|
||||
{
|
||||
return iswprint(c) && c != L' ' && !iswalnum(c);
|
||||
}
|
||||
|
||||
extern "C" int iswspace(wint_t c)
|
||||
{
|
||||
return c == L'\t' || c == L'\n' || c == L'\v' || c == L'\f' || c == L'\r' || c == L' ';
|
||||
}
|
||||
|
||||
extern "C" int iswupper(wint_t c)
|
||||
{
|
||||
return L'A' <= c && c <= L'Z';
|
||||
}
|
||||
|
||||
extern "C" int iswxdigit(wint_t c)
|
||||
{
|
||||
if ( iswdigit(c) ) { return 1; }
|
||||
if ( L'a' <= c && c <= L'f' ) { return 1; }
|
||||
if ( L'A' <= c && c <= L'F' ) { return 1; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" int towlower(wint_t c)
|
||||
{
|
||||
if ( L'A' <= c && c <= L'Z' ) { return L'a' + c - L'A'; }
|
||||
return c;
|
||||
}
|
||||
|
||||
extern "C" int towupper(wint_t c)
|
||||
{
|
||||
if ( L'a' <= c && c <= L'z' ) { return L'A' + c - L'a'; }
|
||||
return c;
|
||||
}
|
||||
|
||||
extern "C" int iswctype(wint_t c, wctype_t wct)
|
||||
{
|
||||
return wct(c);
|
||||
}
|
||||
|
||||
extern "C" wctype_t wctype(const char *name)
|
||||
{
|
||||
if ( !strcmp(name, "alnum") ) return (wctype_t) iswalnum;
|
||||
if ( !strcmp(name, "alpha") ) return (wctype_t) iswalpha;
|
||||
if ( !strcmp(name, "blank") ) return (wctype_t) iswblank;
|
||||
if ( !strcmp(name, "cntrl") ) return (wctype_t) iswcntrl;
|
||||
if ( !strcmp(name, "digit") ) return (wctype_t) iswdigit;
|
||||
if ( !strcmp(name, "graph") ) return (wctype_t) iswgraph;
|
||||
if ( !strcmp(name, "lower") ) return (wctype_t) iswlower;
|
||||
if ( !strcmp(name, "print") ) return (wctype_t) iswprint;
|
||||
if ( !strcmp(name, "punct") ) return (wctype_t) iswpunct;
|
||||
if ( !strcmp(name, "space") ) return (wctype_t) iswspace;
|
||||
if ( !strcmp(name, "upper") ) return (wctype_t) iswupper;
|
||||
if ( !strcmp(name, "xdigit") ) return (wctype_t) iswxdigit;
|
||||
return (wctype_t) 0;
|
||||
}
|
|
@ -141,7 +141,6 @@ typedef __intmax_t __off_t;
|
|||
#define __OFF_MIN __INTMAX_MIN
|
||||
#define __OFF_MAX __INTMAX_MAX
|
||||
typedef unsigned int __wctrans_t; /* TODO: figure out what this does and typedef it properly. This is just a temporary assignment. */
|
||||
typedef unsigned int __wctype_t; /* TODO: figure out what this does and typedef it properly. This is just a temporary assignment. */
|
||||
typedef unsigned int __useconds_t;
|
||||
typedef __off_t __blksize_t;
|
||||
typedef __off_t __blkcnt_t;
|
||||
|
|
|
@ -141,7 +141,6 @@ typedef __intmax_t __off_t;
|
|||
#define __OFF_MIN __INTMAX_MIN
|
||||
#define __OFF_MAX __INTMAX_MAX
|
||||
typedef unsigned int __wctrans_t; /* TODO: figure out what this does and typedef it properly. This is just a temporary assignment. */
|
||||
typedef unsigned int __wctype_t; /* TODO: figure out what this does and typedef it properly. This is just a temporary assignment. */
|
||||
typedef unsigned int __useconds_t;
|
||||
typedef __off_t __blksize_t;
|
||||
typedef __off_t __blkcnt_t;
|
||||
|
|
Loading…
Add table
Reference in a new issue