1*2d08521bSGarrett D'Amore /* 2*2d08521bSGarrett D'Amore * This file and its contents are supplied under the terms of the 3*2d08521bSGarrett D'Amore * Common Development and Distribution License ("CDDL"), version 1.0. 4*2d08521bSGarrett D'Amore * You may only use this file in accordance with the terms of version 5*2d08521bSGarrett D'Amore * 1.0 of the CDDL. 6*2d08521bSGarrett D'Amore * 7*2d08521bSGarrett D'Amore * A full copy of the text of the CDDL should have accompanied this 8*2d08521bSGarrett D'Amore * source. A copy of the CDDL is also available via the Internet at 9*2d08521bSGarrett D'Amore * http://www.illumos.org/license/CDDL. 10*2d08521bSGarrett D'Amore */ 11*2d08521bSGarrett D'Amore 12*2d08521bSGarrett D'Amore /* 13*2d08521bSGarrett D'Amore * Copyright 2013 Garrett D'Amore <garrett@damore.org> 14*2d08521bSGarrett D'Amore * Copyright 2010 Nexenta Systems, Inc. All rights reserved. 15*2d08521bSGarrett D'Amore */ 16*2d08521bSGarrett D'Amore 17*2d08521bSGarrett D'Amore /* 18*2d08521bSGarrett D'Amore * This file contains the implementation of various functional forms 19*2d08521bSGarrett D'Amore * of the ctype tests, specifically the required by ISO C. These are defined 20*2d08521bSGarrett D'Amore * in the "C" (POSIX) locale. 21*2d08521bSGarrett D'Amore */ 22*2d08521bSGarrett D'Amore 23*2d08521bSGarrett D'Amore #include "lint.h" 24*2d08521bSGarrett D'Amore #include <ctype.h> 25*2d08521bSGarrett D'Amore #include <locale.h> 26*2d08521bSGarrett D'Amore #include "localeimpl.h" 27*2d08521bSGarrett D'Amore #include "_ctype.h" 28*2d08521bSGarrett D'Amore #include "lctype.h" 29*2d08521bSGarrett D'Amore 30*2d08521bSGarrett D'Amore /* 31*2d08521bSGarrett D'Amore * We are supplying functional forms, so make sure to suppress any macros 32*2d08521bSGarrett D'Amore * we might have imported. 33*2d08521bSGarrett D'Amore */ 34*2d08521bSGarrett D'Amore 35*2d08521bSGarrett D'Amore /* 36*2d08521bSGarrett D'Amore * Performance note: ASCII test is *much* faster, as we can avoid expensive 37*2d08521bSGarrett D'Amore * function call overhead. This is the hot case, so we try to do that 38*2d08521bSGarrett D'Amore * whenever possible. As far as we know, *every* encoding we support 39*2d08521bSGarrett D'Amore * is a strict superset of ASCII. So we can make things faster by trying 40*2d08521bSGarrett D'Amore * ASCII first, and only then falling to locale specific checks. 41*2d08521bSGarrett D'Amore */ 42*2d08521bSGarrett D'Amore 43*2d08521bSGarrett D'Amore static int 44*2d08521bSGarrett D'Amore isctype_l(int c, int mask, locale_t loc) 45*2d08521bSGarrett D'Amore { 46*2d08521bSGarrett D'Amore return ((unsigned)c > 255 ? 0 : (loc->ctype->lc_ctype_mask[c] & mask)); 47*2d08521bSGarrett D'Amore } 48*2d08521bSGarrett D'Amore 49*2d08521bSGarrett D'Amore #define ISTYPE_L(c, mask, loc) \ 50*2d08521bSGarrett D'Amore (isascii(c) ? (__ctype_mask[c] & (mask)) : isctype_l(c, mask, loc)) 51*2d08521bSGarrett D'Amore 52*2d08521bSGarrett D'Amore #define ISTYPE(c, mask) ISTYPE_L(c, mask, uselocale(NULL)) 53*2d08521bSGarrett D'Amore 54*2d08521bSGarrett D'Amore #define DEFN_ISTYPE(type, mask) \ 55*2d08521bSGarrett D'Amore int \ 56*2d08521bSGarrett D'Amore is##type##_l(int c, locale_t l) \ 57*2d08521bSGarrett D'Amore { \ 58*2d08521bSGarrett D'Amore return (ISTYPE_L(c, mask, l)); \ 59*2d08521bSGarrett D'Amore } \ 60*2d08521bSGarrett D'Amore \ 61*2d08521bSGarrett D'Amore int \ 62*2d08521bSGarrett D'Amore is##type(int c) \ 63*2d08521bSGarrett D'Amore { \ 64*2d08521bSGarrett D'Amore return (ISTYPE(c, mask)); \ 65*2d08521bSGarrett D'Amore } 66*2d08521bSGarrett D'Amore 67*2d08521bSGarrett D'Amore #undef isblank 68*2d08521bSGarrett D'Amore #undef isupper 69*2d08521bSGarrett D'Amore #undef islower 70*2d08521bSGarrett D'Amore #undef isdigit 71*2d08521bSGarrett D'Amore #undef isxdigit 72*2d08521bSGarrett D'Amore #undef isalpha 73*2d08521bSGarrett D'Amore #undef isalnum 74*2d08521bSGarrett D'Amore #undef isspace 75*2d08521bSGarrett D'Amore #undef iscntrl 76*2d08521bSGarrett D'Amore #undef isgraph 77*2d08521bSGarrett D'Amore #undef ispunct 78*2d08521bSGarrett D'Amore #undef isprint 79*2d08521bSGarrett D'Amore 80*2d08521bSGarrett D'Amore DEFN_ISTYPE(blank, _ISBLANK) 81*2d08521bSGarrett D'Amore DEFN_ISTYPE(upper, _ISUPPER) 82*2d08521bSGarrett D'Amore DEFN_ISTYPE(lower, _ISLOWER) 83*2d08521bSGarrett D'Amore DEFN_ISTYPE(digit, _ISDIGIT) 84*2d08521bSGarrett D'Amore DEFN_ISTYPE(xdigit, _ISXDIGIT) 85*2d08521bSGarrett D'Amore DEFN_ISTYPE(alpha, _ISALPHA) 86*2d08521bSGarrett D'Amore DEFN_ISTYPE(alnum, _ISALNUM) 87*2d08521bSGarrett D'Amore DEFN_ISTYPE(space, _ISSPACE) 88*2d08521bSGarrett D'Amore DEFN_ISTYPE(cntrl, _ISCNTRL) 89*2d08521bSGarrett D'Amore DEFN_ISTYPE(graph, _ISGRAPH) 90*2d08521bSGarrett D'Amore DEFN_ISTYPE(punct, _ISPUNCT) 91*2d08521bSGarrett D'Amore DEFN_ISTYPE(print, _ISPRINT) 92