Add ISO C90 Amd. 1 wctype(3) and iswctype(3) functions.
This commit is contained in:
parent
af932613d7
commit
5b32667c57
@ -95,6 +95,11 @@ typedef _BSD_SIZE_T_ size_t;
|
||||
#undef _BSD_SIZE_T_
|
||||
#endif
|
||||
|
||||
#ifndef _WCTYPE_T
|
||||
typedef long wctype_t;
|
||||
#define _WCTYPE_T
|
||||
#endif
|
||||
|
||||
#ifndef WEOF
|
||||
#define WEOF ((wint_t)-1)
|
||||
#endif
|
||||
|
@ -28,24 +28,33 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#if 0
|
||||
/* XXX: not implemented */
|
||||
#ifndef _WCTYPE_H_
|
||||
#define _WCTYPE_H_
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <machine/ansi.h>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef _BSD_WINT_T_
|
||||
typedef _BSD_WINT_T_ wint_t;
|
||||
#undef _BSD_WINT_T_
|
||||
#endif
|
||||
|
||||
#ifndef _WCTYPE_T
|
||||
typedef long wctype_t;
|
||||
#define _WCTYPE_T
|
||||
#endif
|
||||
|
||||
#ifndef WEOF
|
||||
#define WEOF ((wint_t)-1)
|
||||
#endif
|
||||
|
||||
__BEGIN_DECLS
|
||||
int iswctype(wint_t, wctype_t);
|
||||
wctype_t wctype(const char *);
|
||||
#if 0
|
||||
/* XXX: not implemented */
|
||||
int iswalnum(wint_t);
|
||||
int iswalpha(wint_t);
|
||||
int iswblank(wint_t);
|
||||
@ -60,7 +69,9 @@ int iswupper(wint_t);
|
||||
int iswxdigit(wint_t);
|
||||
wint_t towlower(wint_t);
|
||||
wint_t towupper(wint_t);
|
||||
#endif
|
||||
__END_DECLS
|
||||
|
||||
#define iswctype(wc, charclass) __istype((wc), (charclass))
|
||||
|
||||
#endif /* _WCTYPE_H_ */
|
||||
#endif
|
||||
|
@ -9,13 +9,13 @@ SRCS+= ansi.c big5.c collate.c collcmp.c euc.c fix_grouping.c frune.c \
|
||||
ldpart.c lmessages.c lmonetary.c lnumeric.c localeconv.c mbrune.c \
|
||||
mskanji.c nl_langinfo.c nomacros.c none.c rune.c \
|
||||
runetype.c setinvalidrune.c setlocale.c setrunelocale.c table.c \
|
||||
tolower.c toupper.c utf2.c
|
||||
tolower.c toupper.c utf2.c wctype.c
|
||||
|
||||
.if ${LIB} == "c"
|
||||
MAN+= ctype.3 digittoint.3 isalnum.3 isalpha.3 isascii.3 isblank.3 iscntrl.3 \
|
||||
isdigit.3 isgraph.3 islower.3 isprint.3 ispunct.3 isspace.3 \
|
||||
isupper.3 isxdigit.3 mbrune.3 multibyte.3 nl_langinfo.3 rune.3 \
|
||||
setlocale.3 toascii.3 tolower.3 toupper.3
|
||||
setlocale.3 toascii.3 tolower.3 toupper.3 wctype.3
|
||||
MAN+= euc.4 utf2.4
|
||||
|
||||
MLINKS+=isdigit.3 isnumber.3
|
||||
@ -27,4 +27,5 @@ MLINKS+=rune.3 fgetrune.3 rune.3 fputrune.3 rune.3 fungetrune.3 \
|
||||
rune.3 setinvalidrune.3 rune.3 setrunelocale.3 rune.3 sgetrune.3 \
|
||||
rune.3 sputrune.3
|
||||
MLINKS+=setlocale.3 localeconv.3
|
||||
MLINKS+=wctype.3 iswctype.3
|
||||
.endif
|
||||
|
103
lib/libc/locale/wctype.3
Normal file
103
lib/libc/locale/wctype.3
Normal file
@ -0,0 +1,103 @@
|
||||
.\" Copyright (c) 2002 Tim J. Robbins
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd August 3, 2002
|
||||
.Dt WCTYPE 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm iswctype, wctype
|
||||
.Nd "wide character class functions"
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In wctype.h
|
||||
.Ft int
|
||||
.Fn iswctype "wint_t wc" "wctype_t charclass"
|
||||
.Ft wctype_t
|
||||
.Fn wctype "const char *property"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn wctype
|
||||
function returns a value of type
|
||||
.Vt wctype_t
|
||||
which represents the requested wide character class and
|
||||
may be used as the second argument for calls to
|
||||
.Fn iswctype .
|
||||
.Pp
|
||||
The following character class names are recognised:
|
||||
.Bl -column -offset indent ".Li alnum" ".Li cntrl" ".Li phonogram" ".Li print" ".Li special"
|
||||
.It Li alnum Ta Li cntrl Ta Li ideogram Ta Li print Ta Li special
|
||||
.It Li alpha Ta Li digit Ta Li lower Ta Li punct Ta Li upper
|
||||
.It Li blank Ta Li graph Ta Li phonogram Ta Li space Ta Li xdigit
|
||||
.El
|
||||
.Pp
|
||||
The
|
||||
.Fn iswctype
|
||||
function checks whether the wide character
|
||||
.Fa wc
|
||||
is in the character class
|
||||
.Fa charclass .
|
||||
.Sh RETURN VALUES
|
||||
The
|
||||
.Fn iswctype
|
||||
function returns non-zero if and only if
|
||||
.Fa wc
|
||||
has the property described by
|
||||
.Fa charclass ,
|
||||
or
|
||||
.Fa charclass
|
||||
is zero.
|
||||
.Pp
|
||||
The
|
||||
.Fn wctype
|
||||
function returns 0 if
|
||||
.Fa property
|
||||
is invalid, otherwise it returns a value of type
|
||||
.Vt wctype_t
|
||||
that can be used in subsequent calls to
|
||||
.Fn iswctype .
|
||||
.Sh SEE ALSO
|
||||
.Xr ctype 1
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn iswctype
|
||||
and
|
||||
.Fn wctype
|
||||
functions conform to
|
||||
.St -p1003.1-2001 .
|
||||
The
|
||||
.Li ideogram ,
|
||||
.Li phonogram
|
||||
and
|
||||
.Li special
|
||||
character classes are extensions.
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Fn iswctype
|
||||
and
|
||||
.Fn wctype
|
||||
functions first appeared in
|
||||
.Fx 5.0 .
|
73
lib/libc/locale/wctype.c
Normal file
73
lib/libc/locale/wctype.c
Normal file
@ -0,0 +1,73 @@
|
||||
/*-
|
||||
* Copyright (c) 2002 Tim J. Robbins.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <wctype.h>
|
||||
|
||||
#undef iswctype
|
||||
int
|
||||
iswctype(wint_t wc, wctype_t charclass)
|
||||
{
|
||||
|
||||
return (__istype(wc, charclass));
|
||||
}
|
||||
|
||||
wctype_t
|
||||
wctype(const char *property)
|
||||
{
|
||||
struct {
|
||||
const char *name;
|
||||
wctype_t mask;
|
||||
} props[] = {
|
||||
{ "alnum", _CTYPE_A|_CTYPE_D },
|
||||
{ "alpha", _CTYPE_A },
|
||||
{ "blank", _CTYPE_B },
|
||||
{ "cntrl", _CTYPE_C },
|
||||
{ "digit", _CTYPE_D },
|
||||
{ "graph", _CTYPE_G },
|
||||
{ "lower", _CTYPE_L },
|
||||
{ "print", _CTYPE_R },
|
||||
{ "punct", _CTYPE_P },
|
||||
{ "space", _CTYPE_S },
|
||||
{ "upper", _CTYPE_U },
|
||||
{ "xdigit", _CTYPE_X },
|
||||
{ "ideogram", _CTYPE_I }, /* BSD extension */
|
||||
{ "special", _CTYPE_T }, /* BSD extension */
|
||||
{ "phonogram", _CTYPE_Q }, /* BSD extension */
|
||||
{ NULL, 0L }, /* Default */
|
||||
};
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (props[i].name != NULL && strcmp(props[i].name, property) != 0)
|
||||
i++;
|
||||
|
||||
return (props[i].mask);
|
||||
}
|
Loading…
Reference in New Issue
Block a user