ctype.c 6.68 KB
Newer Older
1 2 3 4
/*
 * msvcrt.dll ctype functions
 *
 * Copyright 2000 Jon Griffiths
5 6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 20 21
 */
#include "msvcrt.h"

22
#include "msvcrt/ctype.h"
23

24 25 26
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
27

28
/* Some abbreviations to make the following table readable */
29 30 31 32 33 34 35
#define _C_ _CONTROL
#define _S_ _SPACE
#define _P_ _PUNCT
#define _D_ _DIGIT
#define _H_ _HEX
#define _U_ _UPPER
#define _L_ _LOWER
36 37 38 39

WORD MSVCRT__ctype [257] = {
  0, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _S_|_C_, _S_|_C_,
  _S_|_C_, _S_|_C_, _S_|_C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_,
40
  _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _S_|_BLANK,
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
  _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_,
  _P_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_,
  _D_|_H_, _D_|_H_, _D_|_H_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _U_|_H_,
  _U_|_H_, _U_|_H_, _U_|_H_, _U_|_H_, _U_|_H_, _U_, _U_, _U_, _U_, _U_,
  _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_,
  _U_, _P_, _P_, _P_, _P_, _P_, _P_, _L_|_H_, _L_|_H_, _L_|_H_, _L_|_H_,
  _L_|_H_, _L_|_H_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_,
  _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _P_, _P_, _P_, _P_,
  _C_, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};

/* Internal: Current ctype table for locale */
WORD MSVCRT_current_ctype[257];

/* pctype is used by macros in the Win32 headers. It must point
 * To a table of flags exactly like ctype. To allow locale
 * changes to affect ctypes (i.e. isleadbyte), we use a second table
 * and update its flags whenever the current locale changes.
 */
WORD* MSVCRT__pctype = MSVCRT_current_ctype + 1;

/* mbctype data */
extern int MSVCRT___mb_cur_max;
extern LCID MSVCRT_current_lc_all_lcid;

/*********************************************************************
72
 *		__p__pctype (MSVCRT.@)
73
 */
74
WORD** __p__pctype(void)
75 76 77 78 79 80 81
{
  return &MSVCRT__pctype;
}

/*********************************************************************
 *		_isctype (MSVCRT.@)
 */
82
int _isctype(int c, int type)
83 84 85 86 87 88 89 90 91 92
{
  if (c >= -1 && c <= 255)
    return MSVCRT__pctype[c] & type;

  if (MSVCRT___mb_cur_max != 1 && c > 0)
  {
    /* FIXME: Is there a faster way to do this? */
    WORD typeInfo;
    char convert[3], *pconv = convert;

93
    if (MSVCRT__pctype[(UINT)c >> 8] & _LEADBYTE)
94 95 96 97 98 99 100 101 102 103 104 105 106 107
      *pconv++ = (UINT)c >> 8;
    *pconv++ = c & 0xff;
    *pconv = 0;
    /* FIXME: Use ctype LCID, not lc_all */
    if (GetStringTypeExA(MSVCRT_current_lc_all_lcid, CT_CTYPE1,
                         convert, convert[1] ? 2 : 1, &typeInfo))
      return typeInfo & type;
  }
  return 0;
}

/*********************************************************************
 *		isalnum (MSVCRT.@)
 */
108
int MSVCRT_isalnum(int c)
109
{
110
  return _isctype( c, _ALPHA | _DIGIT );
111 112 113 114 115
}

/*********************************************************************
 *		isalpha (MSVCRT.@)
 */
116
int MSVCRT_isalpha(int c)
117
{
118
  return _isctype( c, _ALPHA );
119 120 121 122 123
}

/*********************************************************************
 *		iscntrl (MSVCRT.@)
 */
124
int MSVCRT_iscntrl(int c)
125
{
126
  return _isctype( c, _CONTROL );
127 128 129 130 131
}

/*********************************************************************
 *		isdigit (MSVCRT.@)
 */
132
int MSVCRT_isdigit(int c)
133
{
134
  return _isctype( c, _DIGIT );
135 136 137 138 139
}

/*********************************************************************
 *		isgraph (MSVCRT.@)
 */
140
int MSVCRT_isgraph(int c)
141
{
142
  return _isctype( c, _ALPHA | _DIGIT | _PUNCT );
143 144 145 146 147
}

/*********************************************************************
 *		isleadbyte (MSVCRT.@)
 */
148
int MSVCRT_isleadbyte(int c)
149
{
150
  return _isctype( c, _LEADBYTE );
151 152 153 154 155
}

/*********************************************************************
 *		islower (MSVCRT.@)
 */
156
int MSVCRT_islower(int c)
157
{
158
  return _isctype( c, _LOWER );
159 160 161 162 163
}

/*********************************************************************
 *		isprint (MSVCRT.@)
 */
164
int MSVCRT_isprint(int c)
165
{
166
  return _isctype( c, _ALPHA | _DIGIT | _BLANK | _PUNCT );
167 168 169 170 171
}

/*********************************************************************
 *		ispunct (MSVCRT.@)
 */
172
int MSVCRT_ispunct(int c)
173
{
174
  return _isctype( c, _PUNCT );
175 176 177 178 179
}

/*********************************************************************
 *		isspace (MSVCRT.@)
 */
180
int MSVCRT_isspace(int c)
181
{
182
  return _isctype( c, _SPACE );
183 184 185 186 187
}

/*********************************************************************
 *		isupper (MSVCRT.@)
 */
188
int MSVCRT_isupper(int c)
189
{
190
  return _isctype( c, _UPPER );
191 192 193 194 195
}

/*********************************************************************
 *		isxdigit (MSVCRT.@)
 */
196
int MSVCRT_isxdigit(int c)
197
{
198
  return _isctype( c, _HEX );
199 200 201 202 203
}

/*********************************************************************
 *		__isascii (MSVCRT.@)
 */
204
int MSVCRT___isascii(int c)
205 206 207 208 209 210 211
{
  return isascii((unsigned)c);
}

/*********************************************************************
 *		__toascii (MSVCRT.@)
 */
212
int MSVCRT___toascii(int c)
213 214 215 216 217 218 219 220
{
  return (unsigned)c & 0x7f;
}

/*********************************************************************
 *		iswascii (MSVCRT.@)
 *
 */
221
int MSVCRT_iswascii(MSVCRT_wchar_t c)
222 223 224 225 226 227 228
{
  return ((unsigned)c < 0x80);
}

/*********************************************************************
 *		__iscsym (MSVCRT.@)
 */
229
int MSVCRT___iscsym(int c)
230 231 232 233 234 235 236
{
  return (c < 127 && (isalnum(c) || c == '_'));
}

/*********************************************************************
 *		__iscsymf (MSVCRT.@)
 */
237
int MSVCRT___iscsymf(int c)
238 239 240 241 242 243 244
{
  return (c < 127 && (isalpha(c) || c == '_'));
}

/*********************************************************************
 *		_toupper (MSVCRT.@)
 */
245
int MSVCRT__toupper(int c)
246
{
247
    return c - 0x20;  /* sic */
248 249 250 251 252
}

/*********************************************************************
 *		_tolower (MSVCRT.@)
 */
253
int MSVCRT__tolower(int c)
254
{
255
    return c + 0x20;  /* sic */
256
}