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 2010 Nexenta Systems, Inc. All rights reserved.
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 * We are supplying functional forms, so make sure to suppress any macros
32 * we might have imported.
36 * Performance note: ASCII test is *much* faster, as we can avoid expensive
37 * function call overhead. This is the hot case, so we try to do that
38 * whenever possible. As far as we know, *every* encoding we support
39 * is a strict superset of ASCII. So we can make things faster by trying
40 * ASCII first, and only then falling to locale specific checks.
44 isctype_l(int c
, int mask
, locale_t loc
)
46 return ((unsigned)c
> 255 ? 0 : (loc
->ctype
->lc_ctype_mask
[c
] & mask
));
49 #define ISTYPE_L(c, mask, loc) \
50 (isascii(c) ? (__ctype_mask[c] & (mask)) : isctype_l(c, mask, loc))
52 #define ISTYPE(c, mask) ISTYPE_L(c, mask, uselocale(NULL))
54 #define DEFN_ISTYPE(type, mask) \
56 is##type##_l(int c, locale_t l) \
58 return (ISTYPE_L(c, mask, l)); \
64 return (ISTYPE(c, mask)); \
80 DEFN_ISTYPE(blank
, _ISBLANK
)
81 DEFN_ISTYPE(upper
, _ISUPPER
)
82 DEFN_ISTYPE(lower
, _ISLOWER
)
83 DEFN_ISTYPE(digit
, _ISDIGIT
)
84 DEFN_ISTYPE(xdigit
, _ISXDIGIT
)
85 DEFN_ISTYPE(alpha
, _ISALPHA
)
86 DEFN_ISTYPE(alnum
, _ISALNUM
)
87 DEFN_ISTYPE(space
, _ISSPACE
)
88 DEFN_ISTYPE(cntrl
, _ISCNTRL
)
89 DEFN_ISTYPE(graph
, _ISGRAPH
)
90 DEFN_ISTYPE(punct
, _ISPUNCT
)
91 DEFN_ISTYPE(print
, _ISPRINT
)