Add the ISO C90 Amd. 1 wctrans(3) and towctrans(3) functions.
This commit is contained in:
parent
92ece88d16
commit
4645079944
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=101313
@ -41,6 +41,11 @@ typedef _BSD_WINT_T_ wint_t;
|
|||||||
#undef _BSD_WINT_T_
|
#undef _BSD_WINT_T_
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef _WCTRANS_T
|
||||||
|
typedef int wctrans_t;
|
||||||
|
#define _WCTRANS_T
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef _WCTYPE_T
|
#ifndef _WCTYPE_T
|
||||||
typedef long wctype_t;
|
typedef long wctype_t;
|
||||||
#define _WCTYPE_T
|
#define _WCTYPE_T
|
||||||
@ -52,6 +57,8 @@ typedef long wctype_t;
|
|||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
int iswctype(wint_t, wctype_t);
|
int iswctype(wint_t, wctype_t);
|
||||||
|
wint_t towctrans(wint_t, wctrans_t);
|
||||||
|
wctrans_t wctrans(const char *);
|
||||||
wctype_t wctype(const char *);
|
wctype_t wctype(const char *);
|
||||||
#if 0
|
#if 0
|
||||||
/* XXX: not implemented */
|
/* XXX: not implemented */
|
||||||
|
@ -9,14 +9,14 @@ SRCS+= ansi.c big5.c btowc.c collate.c collcmp.c euc.c fix_grouping.c frune.c \
|
|||||||
ldpart.c lmessages.c lmonetary.c lnumeric.c localeconv.c mbrune.c \
|
ldpart.c lmessages.c lmonetary.c lnumeric.c localeconv.c mbrune.c \
|
||||||
mskanji.c nl_langinfo.c nomacros.c none.c rune.c \
|
mskanji.c nl_langinfo.c nomacros.c none.c rune.c \
|
||||||
runetype.c setinvalidrune.c setlocale.c setrunelocale.c table.c \
|
runetype.c setinvalidrune.c setlocale.c setrunelocale.c table.c \
|
||||||
tolower.c toupper.c utf2.c wctob.c wctype.c
|
tolower.c toupper.c utf2.c wctob.c wctrans.c wctype.c
|
||||||
|
|
||||||
.if ${LIB} == "c"
|
.if ${LIB} == "c"
|
||||||
MAN+= btowc.3 \
|
MAN+= btowc.3 \
|
||||||
ctype.3 digittoint.3 isalnum.3 isalpha.3 isascii.3 isblank.3 iscntrl.3 \
|
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 \
|
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 \
|
isupper.3 isxdigit.3 mbrune.3 multibyte.3 nl_langinfo.3 rune.3 \
|
||||||
setlocale.3 toascii.3 tolower.3 toupper.3 wctype.3
|
setlocale.3 toascii.3 tolower.3 toupper.3 wctrans.3 wctype.3
|
||||||
MAN+= euc.4 utf2.4
|
MAN+= euc.4 utf2.4
|
||||||
|
|
||||||
MLINKS+=btowc.3 wctob.3
|
MLINKS+=btowc.3 wctob.3
|
||||||
@ -29,5 +29,6 @@ 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 setinvalidrune.3 rune.3 setrunelocale.3 rune.3 sgetrune.3 \
|
||||||
rune.3 sputrune.3
|
rune.3 sputrune.3
|
||||||
MLINKS+=setlocale.3 localeconv.3
|
MLINKS+=setlocale.3 localeconv.3
|
||||||
|
MLINKS+=wctrans.3 towctrans.3
|
||||||
MLINKS+=wctype.3 iswctype.3
|
MLINKS+=wctype.3 iswctype.3
|
||||||
.endif
|
.endif
|
||||||
|
109
lib/libc/locale/wctrans.3
Normal file
109
lib/libc/locale/wctrans.3
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
.\" 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 4, 2002
|
||||||
|
.Dt WCTRANS 3
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm towctrans ,
|
||||||
|
.Nm wctrans
|
||||||
|
.Nd "wide character mapping functions"
|
||||||
|
.Sh LIBRARY
|
||||||
|
.Lb libc
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In wctype.h
|
||||||
|
.Ft wint_t
|
||||||
|
.Fn towctrans "wint_t wc" "wctrans_t desc"
|
||||||
|
.Ft wctrans_t
|
||||||
|
.Fn wctrans "const char *charclass"
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Fn wctrans
|
||||||
|
function returns a value of type
|
||||||
|
.Vt wctrans_t
|
||||||
|
which represents the requested wide character mapping operation and
|
||||||
|
may be used as the second argument for calls to
|
||||||
|
.Fn towctrans .
|
||||||
|
.Pp
|
||||||
|
The following character mapping names are recognised:
|
||||||
|
.Bl -column -offset indent ".Li tolower" ".Li toupper"
|
||||||
|
.It Li tolower Ta Li toupper
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn towctrans
|
||||||
|
function transliterates the wide character
|
||||||
|
.Fa wc
|
||||||
|
according to the mapping described by
|
||||||
|
.Fa desc .
|
||||||
|
.Sh RETURN VALUES
|
||||||
|
The
|
||||||
|
.Fn towctrans
|
||||||
|
function returns the transliterated character if successful, otherwise
|
||||||
|
it returns the character unchanged and sets
|
||||||
|
.Va errno .
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn wctrans
|
||||||
|
function returns non-zero if successful, otherwise it returns zero
|
||||||
|
and sets
|
||||||
|
.Va errno .
|
||||||
|
.Sh ERRORS
|
||||||
|
The
|
||||||
|
.Fn towctrans
|
||||||
|
function will fail if:
|
||||||
|
.Bl -tag -width Er
|
||||||
|
.It Bq Er EINVAL
|
||||||
|
The supplied
|
||||||
|
.Fa desc
|
||||||
|
argument is invalid.
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn wctrans
|
||||||
|
function will fail if:
|
||||||
|
.Bl -tag -width Er
|
||||||
|
.It Bq Er EINVAL
|
||||||
|
The requested mapping name is invalid.
|
||||||
|
.El
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr tolower 3 ,
|
||||||
|
.Xr toupper 3 ,
|
||||||
|
.Xr wctype 3
|
||||||
|
.Sh STANDARDS
|
||||||
|
The
|
||||||
|
.Fn towctrans
|
||||||
|
and
|
||||||
|
.Fn wctrans
|
||||||
|
functions conform to
|
||||||
|
.St -p1003.1-2001 .
|
||||||
|
.Sh HISTORY
|
||||||
|
The
|
||||||
|
.Fn towctrans
|
||||||
|
and
|
||||||
|
.Fn wctrans
|
||||||
|
functions first appeared in
|
||||||
|
.Fx 5.0 .
|
84
lib/libc/locale/wctrans.c
Normal file
84
lib/libc/locale/wctrans.c
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
/*-
|
||||||
|
* 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 <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <wctype.h>
|
||||||
|
|
||||||
|
enum {
|
||||||
|
_WCT_ERROR = 0,
|
||||||
|
_WCT_TOLOWER = 1,
|
||||||
|
_WCT_TOUPPER = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO: Supply a macro version of this.
|
||||||
|
*/
|
||||||
|
wint_t
|
||||||
|
towctrans(wint_t wc, wctrans_t desc)
|
||||||
|
{
|
||||||
|
|
||||||
|
switch (desc) {
|
||||||
|
case _WCT_TOLOWER:
|
||||||
|
wc = tolower(wc);
|
||||||
|
break;
|
||||||
|
case _WCT_TOUPPER:
|
||||||
|
wc = toupper(wc);
|
||||||
|
break;
|
||||||
|
case _WCT_ERROR:
|
||||||
|
default:
|
||||||
|
errno = EINVAL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (wc);
|
||||||
|
}
|
||||||
|
|
||||||
|
wctrans_t
|
||||||
|
wctrans(const char *charclass)
|
||||||
|
{
|
||||||
|
struct {
|
||||||
|
const char *name;
|
||||||
|
wctrans_t trans;
|
||||||
|
} ccls[] = {
|
||||||
|
{ "tolower", _WCT_TOLOWER },
|
||||||
|
{ "toupper", _WCT_TOUPPER },
|
||||||
|
{ NULL, _WCT_ERROR }, /* Default */
|
||||||
|
};
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (ccls[i].name != NULL && strcmp(ccls[i].name, charclass) != 0)
|
||||||
|
i++;
|
||||||
|
|
||||||
|
if (ccls[i].trans == _WCT_ERROR)
|
||||||
|
errno = EINVAL;
|
||||||
|
return (ccls[i].trans);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user