1 /* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. 9 * 10 * This code is derived from software contributed to Berkeley by 11 * Paul Borman at Krystal Technologies. 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 16 * 1. Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 2. Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. 21 * 4. Neither the name of the University nor the names of its contributors 22 * may be used to endorse or promote products derived from this software 23 * without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 */ 37 38 /* 39 * Copyright 2010 Nexenta Systems, Inc. All rights reserved. 40 * Use is subject to license terms. 41 */ 42 43 #include "lint.h" 44 #include <wctype.h> 45 #include "runefile.h" 46 #include "runetype.h" 47 #include "_ctype.h" 48 49 /* 50 * We removed: iswascii, iswrune, iswhexnumber, and iswnumber, as 51 * these are not present on Solaris. Note that the standard requires 52 * iswascii to be a macro, so it is defined in our headers. 53 * 54 * We renamed (per Solaris) iswideogram, iswspecial, iswspecial to the 55 * equivalent values without "w". We added a new isnumber, that looks 56 * for non-ASCII numbers. 57 */ 58 59 static int 60 __istype(wint_t c, unsigned int f) 61 { 62 unsigned int rt; 63 64 /* Fast path for single byte locales */ 65 if (c < 0 || c >= _CACHED_RUNES) 66 rt = ___runetype(c); 67 else 68 rt = _CurrentRuneLocale->__runetype[c]; 69 return (rt & f); 70 } 71 72 static int 73 __isctype(wint_t c, unsigned int f) 74 { 75 unsigned int rt; 76 77 /* Fast path for single byte locales */ 78 if (c < 0 || c >= _CACHED_RUNES) 79 return (0); 80 else 81 rt = _CurrentRuneLocale->__runetype[c]; 82 return (rt & f); 83 } 84 85 #undef iswctype 86 int 87 iswctype(wint_t wc, wctype_t class) 88 { 89 return (__istype(wc, class)); 90 } 91 92 #undef _iswctype 93 unsigned 94 _iswctype(wchar_t wc, int class) 95 { 96 return (__istype((wint_t)wc, (unsigned int)class)); 97 } 98 99 #undef iswalnum 100 int 101 iswalnum(wint_t wc) 102 { 103 return (__istype(wc, _CTYPE_A|_CTYPE_D)); 104 } 105 106 #undef iswalpha 107 int 108 iswalpha(wint_t wc) 109 { 110 return (__istype(wc, _CTYPE_A)); 111 } 112 113 #undef iswblank 114 int 115 iswblank(wint_t wc) 116 { 117 return (__istype(wc, _CTYPE_B)); 118 } 119 120 #undef iswcntrl 121 int 122 iswcntrl(wint_t wc) 123 { 124 return (__istype(wc, _CTYPE_C)); 125 } 126 127 #undef iswdigit 128 int 129 iswdigit(wint_t wc) 130 { 131 return (__isctype(wc, _CTYPE_D)); 132 } 133 134 #undef iswgraph 135 int 136 iswgraph(wint_t wc) 137 { 138 return (__istype(wc, _CTYPE_G)); 139 } 140 141 #undef isideogram 142 int 143 isideogram(wint_t wc) 144 { 145 return (__istype(wc, _CTYPE_I)); 146 } 147 148 #undef iswlower 149 int 150 iswlower(wint_t wc) 151 { 152 return (__istype(wc, _CTYPE_L)); 153 } 154 155 #undef isphonogram 156 int 157 isphonogram(wint_t wc) 158 { 159 return (__istype(wc, _CTYPE_Q)); 160 } 161 162 #undef iswprint 163 int 164 iswprint(wint_t wc) 165 { 166 return (__istype(wc, _CTYPE_R)); 167 } 168 169 #undef iswpunct 170 int 171 iswpunct(wint_t wc) 172 { 173 return (__istype(wc, _CTYPE_P)); 174 } 175 176 #undef iswspace 177 int 178 iswspace(wint_t wc) 179 { 180 return (__istype(wc, _CTYPE_S)); 181 } 182 183 #undef iswupper 184 int 185 iswupper(wint_t wc) 186 { 187 return (__istype(wc, _CTYPE_U)); 188 } 189 190 #undef iswxdigit 191 int 192 iswxdigit(wint_t wc) 193 { 194 return (__isctype(wc, _CTYPE_X)); 195 } 196 197 #undef isenglish 198 int 199 isenglish(wint_t wc) 200 { 201 return (__istype(wc, _CTYPE_E)); 202 } 203 204 #undef isspecial 205 int 206 isspecial(wint_t wc) 207 { 208 return (__istype(wc, _CTYPE_T)); 209 } 210 211 #undef isnumber 212 int 213 isnumber(wint_t wc) 214 { 215 return (__istype(wc, _CTYPE_N)); 216 } 217