2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2013 Garrett D'Amore <garrett@damore.org>
14 * Copyright 2017 Nexenta Systems, Inc.
18 * This file contains the implementation of various functional forms
19 * of the ctype tests, specifically the required by ISO C. These are defined
20 * in the "C" (POSIX) locale.
26 #include "localeimpl.h"
31 * As far as we know, *every* encoding we support is a strict superset of ASCII,
32 * so we can make things faster by trying ASCII first. Next check if argument
33 * can be represented as unsigned char, and that locale is not multibyte - every
34 * multibyte encoding we support has non-ASCII code points undefined. Finally,
35 * lookup the result in locale specific table.
37 #define ISTYPE_L(c, mask, loc) \
38 (isascii(c) ? (__ctype_mask[c] & (mask)) : \
39 ((unsigned)c > 255 || loc->ctype->lc_max_mblen > 1) ? 0 : \
40 (loc->ctype->lc_ctype_mask[c] & mask))
42 #define ISTYPE(c, mask) ISTYPE_L(c, mask, uselocale(NULL))
44 #define DEFN_ISTYPE(type, mask) \
46 is##type##_l(int c, locale_t l) \
48 return (ISTYPE_L(c, mask, l)); \
54 return (ISTYPE(c, mask)); \
58 * We are supplying functional forms, so make sure to suppress any macros
59 * we might have imported.
74 DEFN_ISTYPE(blank
, _ISBLANK
)
75 DEFN_ISTYPE(upper
, _ISUPPER
)
76 DEFN_ISTYPE(lower
, _ISLOWER
)
77 DEFN_ISTYPE(digit
, _ISDIGIT
)
78 DEFN_ISTYPE(xdigit
, _ISXDIGIT
)
79 DEFN_ISTYPE(alpha
, _ISALPHA
)
80 DEFN_ISTYPE(alnum
, _ISALNUM
)
81 DEFN_ISTYPE(space
, _ISSPACE
)
82 DEFN_ISTYPE(cntrl
, _ISCNTRL
)
83 DEFN_ISTYPE(graph
, _ISGRAPH
)
84 DEFN_ISTYPE(punct
, _ISPUNCT
)
85 DEFN_ISTYPE(print
, _ISPRINT
)