1 /* Copyright (C) 2000 MySQL AB 2 3 This program is free software; you can redistribute it and/or modify 4 it under the terms of the GNU General Public License as published by 5 the Free Software Foundation; either version 2 of the License, or 6 (at your option) any later version. 7 8 This program is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License 14 along with this program; if not, write to the Free Software 15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 16 17 /* 18 A better inplementation of the UNIX ctype(3) library. 19 Notes: my_global.h should be included before ctype.h 20 */ 21 22 #ifndef _m_ctype_h 23 #define _m_ctype_h 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 #define CHARSET_DIR "charsets/" 30 31 typedef struct charset_info_st 32 { 33 uint number; 34 const char *name; 35 uchar *ctype; 36 uchar *to_lower; 37 uchar *to_upper; 38 uchar *sort_order; 39 40 uint strxfrm_multiply; 41 int (*strcoll)(const uchar *, const uchar *); 42 int (*strxfrm)(uchar *, const uchar *, int); 43 int (*strnncoll)(const uchar *, int, const uchar *, int); 44 int (*strnxfrm)(uchar *, const uchar *, int, int); 45 my_bool (*like_range)(const char *, uint, pchar, uint, 46 char *, char *, uint *, uint *); 47 48 uint mbmaxlen; 49 int (*ismbchar)(const char *, const char *); 50 my_bool (*ismbhead)(uint); 51 int (*mbcharlen)(uint); 52 } CHARSET_INFO; 53 54 /* strings/ctype.c */ 55 extern CHARSET_INFO *default_charset_info; 56 extern CHARSET_INFO *find_compiled_charset(uint cs_number); 57 extern CHARSET_INFO *find_compiled_charset_by_name(const char *name); 58 extern CHARSET_INFO compiled_charsets[]; 59 extern uint compiled_charset_number(const char *name); 60 extern const char *compiled_charset_name(uint charset_number); 61 62 #define MY_CHARSET_UNDEFINED 0 63 #define MY_CHARSET_CURRENT (default_charset_info->number) 64 65 /* Don't include std ctype.h when this is included */ 66 #define _CTYPE_H 67 #define _CTYPE_H_ 68 #define _CTYPE_INCLUDED 69 #define __CTYPE_INCLUDED 70 #define _CTYPE_USING /* Don't put names in global namespace. */ 71 72 /* Fix things, if ctype.h would have been included before */ 73 #undef toupper 74 #undef _toupper 75 #undef _tolower 76 #undef toupper 77 #undef tolower 78 #undef isalpha 79 #undef isupper 80 #undef islower 81 #undef isdigit 82 #undef isxdigit 83 #undef isalnum 84 #undef isspace 85 #undef ispunct 86 #undef isprint 87 #undef isgraph 88 #undef iscntrl 89 #undef isascii 90 #undef toascii 91 92 #define _U 01 /* Upper case */ 93 #define _L 02 /* Lower case */ 94 #define _NMR 04 /* Numeral (digit) */ 95 #define _SPC 010 /* Spacing character */ 96 #define _PNT 020 /* Punctuation */ 97 #define _CTR 040 /* Control character */ 98 #define _B 0100 /* Blank */ 99 #define _X 0200 /* heXadecimal digit */ 100 101 #define my_ctype (default_charset_info->ctype) 102 #define my_to_upper (default_charset_info->to_upper) 103 #define my_to_lower (default_charset_info->to_lower) 104 #define my_sort_order (default_charset_info->sort_order) 105 106 #define _toupper(c) (char) my_to_upper[(uchar) (c)] 107 #define _tolower(c) (char) my_to_lower[(uchar) (c)] 108 #define toupper(c) (char) my_to_upper[(uchar) (c)] 109 #define tolower(c) (char) my_to_lower[(uchar) (c)] 110 111 #define isalpha(c) ((my_ctype+1)[(uchar) (c)] & (_U | _L)) 112 #define isupper(c) ((my_ctype+1)[(uchar) (c)] & _U) 113 #define islower(c) ((my_ctype+1)[(uchar) (c)] & _L) 114 #define isdigit(c) ((my_ctype+1)[(uchar) (c)] & _NMR) 115 #define isxdigit(c) ((my_ctype+1)[(uchar) (c)] & _X) 116 #define isalnum(c) ((my_ctype+1)[(uchar) (c)] & (_U | _L | _NMR)) 117 #define isspace(c) ((my_ctype+1)[(uchar) (c)] & _SPC) 118 #define ispunct(c) ((my_ctype+1)[(uchar) (c)] & _PNT) 119 #define isprint(c) ((my_ctype+1)[(uchar) (c)] & (_PNT | _U | _L | _NMR | _B)) 120 #define isgraph(c) ((my_ctype+1)[(uchar) (c)] & (_PNT | _U | _L | _NMR)) 121 #define iscntrl(c) ((my_ctype+1)[(uchar) (c)] & _CTR) 122 #define isascii(c) (!((c) & ~0177)) 123 #define toascii(c) ((c) & 0177) 124 125 #ifdef ctype 126 #undef ctype 127 #endif /* ctype */ 128 129 #define my_isalpha(s, c) (((s)->ctype+1)[(uchar) (c)] & (_U | _L)) 130 #define my_isupper(s, c) (((s)->ctype+1)[(uchar) (c)] & _U) 131 #define my_islower(s, c) (((s)->ctype+1)[(uchar) (c)] & _L) 132 #define my_isdigit(s, c) (((s)->ctype+1)[(uchar) (c)] & _NMR) 133 #define my_isxdigit(s, c) (((s)->ctype+1)[(uchar) (c)] & _X) 134 #define my_isalnum(s, c) (((s)->ctype+1)[(uchar) (c)] & (_U | _L | _NMR)) 135 #define my_isspace(s, c) (((s)->ctype+1)[(uchar) (c)] & _SPC) 136 #define my_ispunct(s, c) (((s)->ctype+1)[(uchar) (c)] & _PNT) 137 #define my_isprint(s, c) (((s)->ctype+1)[(uchar) (c)] & (_PNT | _U | _L | _NMR | _B)) 138 #define my_isgraph(s, c) (((s)->ctype+1)[(uchar) (c)] & (_PNT | _U | _L | _NMR)) 139 #define my_iscntrl(s, c) (((s)->ctype+1)[(uchar) (c)] & _CTR) 140 141 #define use_strcoll(s) ((s)->strcoll != NULL) 142 #define MY_STRXFRM_MULTIPLY (default_charset_info->strxfrm_multiply) 143 #define my_strnxfrm(s, a, b, c, d) ((s)->strnxfrm((a), (b), (c), (d))) 144 #define my_strnncoll(s, a, b, c, d) ((s)->strnncoll((a), (b), (c), (d))) 145 #define my_strcoll(s, a, b) ((s)->strcoll((a), (b))) 146 #define my_like_range(s, a, b, c, d, e, f, g, h) \ 147 ((s)->like_range((a), (b), (c), (d), (e), (f), (g), (h))) 148 149 #define use_mb(s) ((s)->ismbchar != NULL) 150 #define MBMAXLEN (default_charset_info->mbmaxlen) 151 #define my_ismbchar(s, a, b) ((s)->ismbchar((a), (b))) 152 #define my_ismbhead(s, a) ((s)->ismbhead((a))) 153 #define my_mbcharlen(s, a) ((s)->mbcharlen((a))) 154 155 /* Some macros that should be cleaned up a little */ 156 #define isvar(c) (isalnum(c) || (c) == '_') 157 #define isvar_start(c) (isalpha(c) || (c) == '_') 158 #define tocntrl(c) ((c) & 31) 159 #define toprint(c) ((c) | 64) 160 161 /* XXX: still need to take care of this one */ 162 #ifdef MY_CHARSET_TIS620 163 #error The TIS620 charset is broken at the moment. Tell tim to fix it. 164 #define USE_TIS620 165 #include "t_ctype.h" 166 #endif 167 168 #ifdef __cplusplus 169 } 170 #endif 171 172 #endif /* _m_ctype_h */ 173