m_ctype.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. /* Copyright (C) 2000 MySQL AB
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  12. /*
  13. A better inplementation of the UNIX ctype(3) library.
  14. Notes: my_global.h should be included before ctype.h
  15. */
  16. #ifndef _m_ctype_h
  17. #define _m_ctype_h
  18. #include <my_attribute.h>
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. #define MY_CS_NAME_SIZE 32
  23. #define MY_CS_CTYPE_TABLE_SIZE 257
  24. #define MY_CS_TO_LOWER_TABLE_SIZE 256
  25. #define MY_CS_TO_UPPER_TABLE_SIZE 256
  26. #define MY_CS_SORT_ORDER_TABLE_SIZE 256
  27. #define MY_CS_TO_UNI_TABLE_SIZE 256
  28. #define CHARSET_DIR "charsets/"
  29. #define my_wc_t ulong
  30. typedef struct unicase_info_st
  31. {
  32. uint16 toupper;
  33. uint16 tolower;
  34. uint16 sort;
  35. } MY_UNICASE_INFO;
  36. extern MY_UNICASE_INFO *my_unicase_default[256];
  37. extern MY_UNICASE_INFO *my_unicase_turkish[256];
  38. typedef struct uni_ctype_st
  39. {
  40. uchar pctype;
  41. uchar *ctype;
  42. } MY_UNI_CTYPE;
  43. extern MY_UNI_CTYPE my_uni_ctype[256];
  44. /* wm_wc and wc_mb return codes */
  45. #define MY_CS_ILSEQ 0 /* Wrong by sequence: wb_wc */
  46. #define MY_CS_ILUNI 0 /* Cannot encode Unicode to charset: wc_mb */
  47. #define MY_CS_TOOSMALL -101 /* Need at least one byte: wc_mb and mb_wc */
  48. #define MY_CS_TOOSMALL2 -102 /* Need at least two bytes: wc_mb and mb_wc */
  49. #define MY_CS_TOOSMALL3 -103 /* Need at least three bytes: wc_mb and mb_wc */
  50. /* These following three are currently not really used */
  51. #define MY_CS_TOOSMALL4 -104 /* Need at least 4 bytes: wc_mb and mb_wc */
  52. #define MY_CS_TOOSMALL5 -105 /* Need at least 5 bytes: wc_mb and mb_wc */
  53. #define MY_CS_TOOSMALL6 -106 /* Need at least 6 bytes: wc_mb and mb_wc */
  54. /* A helper macros for "need at least n bytes" */
  55. #define MY_CS_TOOSMALLN(n) (-100-(n))
  56. #define MY_SEQ_INTTAIL 1
  57. #define MY_SEQ_SPACES 2
  58. /* My charsets_list flags */
  59. #define MY_CS_COMPILED 1 /* compiled-in sets */
  60. #define MY_CS_CONFIG 2 /* sets that have a *.conf file */
  61. #define MY_CS_INDEX 4 /* sets listed in the Index file */
  62. #define MY_CS_LOADED 8 /* sets that are currently loaded */
  63. #define MY_CS_BINSORT 16 /* if binary sort order */
  64. #define MY_CS_PRIMARY 32 /* if primary collation */
  65. #define MY_CS_STRNXFRM 64 /* if strnxfrm is used for sort */
  66. #define MY_CS_UNICODE 128 /* is a charset is full unicode */
  67. #define MY_CS_READY 256 /* if a charset is initialized */
  68. #define MY_CS_AVAILABLE 512 /* If either compiled-in or loaded*/
  69. #define MY_CS_CSSORT 1024 /* if case sensitive sort order */
  70. #define MY_CS_HIDDEN 2048 /* don't display in SHOW */
  71. #define MY_CS_PUREASCII 4096 /* if a charset is pure ascii */
  72. #define MY_CHARSET_UNDEFINED 0
  73. /* Character repertoire flags */
  74. #define MY_REPERTOIRE_ASCII 1 /* Pure ASCII U+0000..U+007F */
  75. #define MY_REPERTOIRE_EXTENDED 2 /* Extended characters: U+0080..U+FFFF */
  76. #define MY_REPERTOIRE_UNICODE30 3 /* ASCII | EXTENDED: U+0000..U+FFFF */
  77. typedef struct my_uni_idx_st
  78. {
  79. uint16 from;
  80. uint16 to;
  81. uchar *tab;
  82. } MY_UNI_IDX;
  83. typedef struct
  84. {
  85. uint beg;
  86. uint end;
  87. uint mb_len;
  88. } my_match_t;
  89. enum my_lex_states
  90. {
  91. MY_LEX_START, MY_LEX_CHAR, MY_LEX_IDENT,
  92. MY_LEX_IDENT_SEP, MY_LEX_IDENT_START,
  93. MY_LEX_REAL, MY_LEX_HEX_NUMBER, MY_LEX_BIN_NUMBER,
  94. MY_LEX_CMP_OP, MY_LEX_LONG_CMP_OP, MY_LEX_STRING, MY_LEX_COMMENT, MY_LEX_END,
  95. MY_LEX_OPERATOR_OR_IDENT, MY_LEX_NUMBER_IDENT, MY_LEX_INT_OR_REAL,
  96. MY_LEX_REAL_OR_POINT, MY_LEX_BOOL, MY_LEX_EOL, MY_LEX_ESCAPE,
  97. MY_LEX_LONG_COMMENT, MY_LEX_END_LONG_COMMENT, MY_LEX_SEMICOLON,
  98. MY_LEX_SET_VAR, MY_LEX_USER_END, MY_LEX_HOSTNAME, MY_LEX_SKIP,
  99. MY_LEX_USER_VARIABLE_DELIMITER, MY_LEX_SYSTEM_VAR,
  100. MY_LEX_IDENT_OR_KEYWORD,
  101. MY_LEX_IDENT_OR_HEX, MY_LEX_IDENT_OR_BIN, MY_LEX_IDENT_OR_NCHAR,
  102. MY_LEX_STRING_OR_DELIMITER
  103. };
  104. struct charset_info_st;
  105. /* See strings/CHARSET_INFO.txt for information about this structure */
  106. typedef struct my_collation_handler_st
  107. {
  108. my_bool (*init)(struct charset_info_st *, void *(*alloc)(size_t));
  109. /* Collation routines */
  110. int (*strnncoll)(struct charset_info_st *,
  111. const uchar *, size_t, const uchar *, size_t, my_bool);
  112. int (*strnncollsp)(struct charset_info_st *,
  113. const uchar *, size_t, const uchar *, size_t,
  114. my_bool diff_if_only_endspace_difference);
  115. size_t (*strnxfrm)(struct charset_info_st *,
  116. uchar *, size_t, const uchar *, size_t);
  117. size_t (*strnxfrmlen)(struct charset_info_st *, size_t);
  118. my_bool (*like_range)(struct charset_info_st *,
  119. const char *s, size_t s_length,
  120. pchar w_prefix, pchar w_one, pchar w_many,
  121. size_t res_length,
  122. char *min_str, char *max_str,
  123. size_t *min_len, size_t *max_len);
  124. int (*wildcmp)(struct charset_info_st *,
  125. const char *str,const char *str_end,
  126. const char *wildstr,const char *wildend,
  127. int escape,int w_one, int w_many);
  128. int (*strcasecmp)(struct charset_info_st *, const char *, const char *);
  129. uint (*instr)(struct charset_info_st *,
  130. const char *b, size_t b_length,
  131. const char *s, size_t s_length,
  132. my_match_t *match, uint nmatch);
  133. /* Hash calculation */
  134. void (*hash_sort)(struct charset_info_st *cs, const uchar *key, size_t len,
  135. ulong *nr1, ulong *nr2);
  136. my_bool (*propagate)(struct charset_info_st *cs, const uchar *str, size_t len);
  137. } MY_COLLATION_HANDLER;
  138. extern MY_COLLATION_HANDLER my_collation_mb_bin_handler;
  139. extern MY_COLLATION_HANDLER my_collation_8bit_bin_handler;
  140. extern MY_COLLATION_HANDLER my_collation_8bit_simple_ci_handler;
  141. extern MY_COLLATION_HANDLER my_collation_ucs2_uca_handler;
  142. /* Some typedef to make it easy for C++ to make function pointers */
  143. typedef int (*my_charset_conv_mb_wc)(struct charset_info_st *, my_wc_t *,
  144. const uchar *, const uchar *);
  145. typedef int (*my_charset_conv_wc_mb)(struct charset_info_st *, my_wc_t,
  146. uchar *, uchar *);
  147. typedef size_t (*my_charset_conv_case)(struct charset_info_st *,
  148. char *, size_t, char *, size_t);
  149. /* See strings/CHARSET_INFO.txt about information on this structure */
  150. typedef struct my_charset_handler_st
  151. {
  152. my_bool (*init)(struct charset_info_st *, void *(*alloc)(size_t));
  153. /* Multibyte routines */
  154. uint (*ismbchar)(struct charset_info_st *, const char *, const char *);
  155. uint (*mbcharlen)(struct charset_info_st *, uint c);
  156. size_t (*numchars)(struct charset_info_st *, const char *b, const char *e);
  157. size_t (*charpos)(struct charset_info_st *, const char *b, const char *e,
  158. size_t pos);
  159. size_t (*well_formed_len)(struct charset_info_st *,
  160. const char *b,const char *e,
  161. size_t nchars, int *error);
  162. size_t (*lengthsp)(struct charset_info_st *, const char *ptr, size_t length);
  163. size_t (*numcells)(struct charset_info_st *, const char *b, const char *e);
  164. /* Unicode conversion */
  165. my_charset_conv_mb_wc mb_wc;
  166. my_charset_conv_wc_mb wc_mb;
  167. /* CTYPE scanner */
  168. int (*ctype)(struct charset_info_st *cs, int *ctype,
  169. const uchar *s, const uchar *e);
  170. /* Functions for case and sort conversion */
  171. size_t (*caseup_str)(struct charset_info_st *, char *);
  172. size_t (*casedn_str)(struct charset_info_st *, char *);
  173. my_charset_conv_case caseup;
  174. my_charset_conv_case casedn;
  175. /* Charset dependant snprintf() */
  176. size_t (*snprintf)(struct charset_info_st *, char *to, size_t n,
  177. const char *fmt,
  178. ...) ATTRIBUTE_FORMAT_FPTR(printf, 4, 5);
  179. size_t (*long10_to_str)(struct charset_info_st *, char *to, size_t n,
  180. int radix, long int val);
  181. size_t (*longlong10_to_str)(struct charset_info_st *, char *to, size_t n,
  182. int radix, longlong val);
  183. void (*fill)(struct charset_info_st *, char *to, size_t len, int fill);
  184. /* String-to-number conversion routines */
  185. long (*strntol)(struct charset_info_st *, const char *s, size_t l,
  186. int base, char **e, int *err);
  187. ulong (*strntoul)(struct charset_info_st *, const char *s, size_t l,
  188. int base, char **e, int *err);
  189. longlong (*strntoll)(struct charset_info_st *, const char *s, size_t l,
  190. int base, char **e, int *err);
  191. ulonglong (*strntoull)(struct charset_info_st *, const char *s, size_t l,
  192. int base, char **e, int *err);
  193. double (*strntod)(struct charset_info_st *, char *s, size_t l, char **e,
  194. int *err);
  195. longlong (*strtoll10)(struct charset_info_st *cs,
  196. const char *nptr, char **endptr, int *error);
  197. ulonglong (*strntoull10rnd)(struct charset_info_st *cs,
  198. const char *str, size_t length,
  199. int unsigned_fl,
  200. char **endptr, int *error);
  201. size_t (*scan)(struct charset_info_st *, const char *b, const char *e,
  202. int sq);
  203. } MY_CHARSET_HANDLER;
  204. extern MY_CHARSET_HANDLER my_charset_8bit_handler;
  205. extern MY_CHARSET_HANDLER my_charset_ucs2_handler;
  206. /* See strings/CHARSET_INFO.txt about information on this structure */
  207. typedef struct charset_info_st
  208. {
  209. uint number;
  210. uint primary_number;
  211. uint binary_number;
  212. uint state;
  213. const char *csname;
  214. const char *name;
  215. const char *comment;
  216. const char *tailoring;
  217. uchar *ctype;
  218. uchar *to_lower;
  219. uchar *to_upper;
  220. uchar *sort_order;
  221. uint16 *contractions;
  222. uint16 **sort_order_big;
  223. uint16 *tab_to_uni;
  224. MY_UNI_IDX *tab_from_uni;
  225. MY_UNICASE_INFO **caseinfo;
  226. uchar *state_map;
  227. uchar *ident_map;
  228. uint strxfrm_multiply;
  229. uchar caseup_multiply;
  230. uchar casedn_multiply;
  231. uint mbminlen;
  232. uint mbmaxlen;
  233. uint16 min_sort_char;
  234. uint16 max_sort_char; /* For LIKE optimization */
  235. uchar pad_char;
  236. my_bool escape_with_backslash_is_dangerous;
  237. MY_CHARSET_HANDLER *cset;
  238. MY_COLLATION_HANDLER *coll;
  239. } CHARSET_INFO;
  240. #define ILLEGAL_CHARSET_INFO_NUMBER (~0U)
  241. extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_bin;
  242. extern CHARSET_INFO my_charset_big5_chinese_ci;
  243. extern CHARSET_INFO my_charset_big5_bin;
  244. extern CHARSET_INFO my_charset_cp932_japanese_ci;
  245. extern CHARSET_INFO my_charset_cp932_bin;
  246. extern CHARSET_INFO my_charset_eucjpms_japanese_ci;
  247. extern CHARSET_INFO my_charset_eucjpms_bin;
  248. extern CHARSET_INFO my_charset_euckr_korean_ci;
  249. extern CHARSET_INFO my_charset_euckr_bin;
  250. extern CHARSET_INFO my_charset_gb2312_chinese_ci;
  251. extern CHARSET_INFO my_charset_gb2312_bin;
  252. extern CHARSET_INFO my_charset_gbk_chinese_ci;
  253. extern CHARSET_INFO my_charset_gbk_bin;
  254. extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_latin1;
  255. extern CHARSET_INFO my_charset_latin1_german2_ci;
  256. extern CHARSET_INFO my_charset_latin1_bin;
  257. extern CHARSET_INFO my_charset_latin2_czech_ci;
  258. extern CHARSET_INFO my_charset_sjis_japanese_ci;
  259. extern CHARSET_INFO my_charset_sjis_bin;
  260. extern CHARSET_INFO my_charset_tis620_thai_ci;
  261. extern CHARSET_INFO my_charset_tis620_bin;
  262. extern CHARSET_INFO my_charset_ucs2_general_ci;
  263. extern CHARSET_INFO my_charset_ucs2_bin;
  264. extern CHARSET_INFO my_charset_ucs2_unicode_ci;
  265. extern CHARSET_INFO my_charset_ujis_japanese_ci;
  266. extern CHARSET_INFO my_charset_ujis_bin;
  267. extern CHARSET_INFO my_charset_utf8_general_ci;
  268. extern CHARSET_INFO my_charset_utf8_unicode_ci;
  269. extern CHARSET_INFO my_charset_utf8_bin;
  270. extern CHARSET_INFO my_charset_cp1250_czech_ci;
  271. extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_filename;
  272. /* declarations for simple charsets */
  273. extern size_t my_strnxfrm_simple(CHARSET_INFO *, uchar *, size_t,
  274. const uchar *, size_t);
  275. size_t my_strnxfrmlen_simple(CHARSET_INFO *, size_t);
  276. extern int my_strnncoll_simple(CHARSET_INFO *, const uchar *, size_t,
  277. const uchar *, size_t, my_bool);
  278. extern int my_strnncollsp_simple(CHARSET_INFO *, const uchar *, size_t,
  279. const uchar *, size_t,
  280. my_bool diff_if_only_endspace_difference);
  281. extern void my_hash_sort_simple(CHARSET_INFO *cs,
  282. const uchar *key, size_t len,
  283. ulong *nr1, ulong *nr2);
  284. extern size_t my_lengthsp_8bit(CHARSET_INFO *cs, const char *ptr, size_t length);
  285. extern uint my_instr_simple(struct charset_info_st *,
  286. const char *b, size_t b_length,
  287. const char *s, size_t s_length,
  288. my_match_t *match, uint nmatch);
  289. /* Functions for 8bit */
  290. extern size_t my_caseup_str_8bit(CHARSET_INFO *, char *);
  291. extern size_t my_casedn_str_8bit(CHARSET_INFO *, char *);
  292. extern size_t my_caseup_8bit(CHARSET_INFO *, char *src, size_t srclen,
  293. char *dst, size_t dstlen);
  294. extern size_t my_casedn_8bit(CHARSET_INFO *, char *src, size_t srclen,
  295. char *dst, size_t dstlen);
  296. extern int my_strcasecmp_8bit(CHARSET_INFO * cs, const char *, const char *);
  297. int my_mb_wc_8bit(CHARSET_INFO *cs,my_wc_t *wc, const uchar *s,const uchar *e);
  298. int my_wc_mb_8bit(CHARSET_INFO *cs,my_wc_t wc, uchar *s, uchar *e);
  299. int my_mb_ctype_8bit(CHARSET_INFO *,int *, const uchar *,const uchar *);
  300. int my_mb_ctype_mb(CHARSET_INFO *,int *, const uchar *,const uchar *);
  301. size_t my_scan_8bit(CHARSET_INFO *cs, const char *b, const char *e, int sq);
  302. size_t my_snprintf_8bit(struct charset_info_st *, char *to, size_t n,
  303. const char *fmt, ...)
  304. ATTRIBUTE_FORMAT(printf, 4, 5);
  305. long my_strntol_8bit(CHARSET_INFO *, const char *s, size_t l, int base,
  306. char **e, int *err);
  307. ulong my_strntoul_8bit(CHARSET_INFO *, const char *s, size_t l, int base,
  308. char **e, int *err);
  309. longlong my_strntoll_8bit(CHARSET_INFO *, const char *s, size_t l, int base,
  310. char **e, int *err);
  311. ulonglong my_strntoull_8bit(CHARSET_INFO *, const char *s, size_t l, int base,
  312. char **e, int *err);
  313. double my_strntod_8bit(CHARSET_INFO *, char *s, size_t l,char **e,
  314. int *err);
  315. size_t my_long10_to_str_8bit(CHARSET_INFO *, char *to, size_t l, int radix,
  316. long int val);
  317. size_t my_longlong10_to_str_8bit(CHARSET_INFO *, char *to, size_t l, int radix,
  318. longlong val);
  319. longlong my_strtoll10_8bit(CHARSET_INFO *cs,
  320. const char *nptr, char **endptr, int *error);
  321. longlong my_strtoll10_ucs2(CHARSET_INFO *cs,
  322. const char *nptr, char **endptr, int *error);
  323. ulonglong my_strntoull10rnd_8bit(CHARSET_INFO *cs,
  324. const char *str, size_t length, int
  325. unsigned_fl, char **endptr, int *error);
  326. ulonglong my_strntoull10rnd_ucs2(CHARSET_INFO *cs,
  327. const char *str, size_t length,
  328. int unsigned_fl, char **endptr, int *error);
  329. void my_fill_8bit(CHARSET_INFO *cs, char* to, size_t l, int fill);
  330. my_bool my_like_range_simple(CHARSET_INFO *cs,
  331. const char *ptr, size_t ptr_length,
  332. pbool escape, pbool w_one, pbool w_many,
  333. size_t res_length,
  334. char *min_str, char *max_str,
  335. size_t *min_length, size_t *max_length);
  336. my_bool my_like_range_mb(CHARSET_INFO *cs,
  337. const char *ptr, size_t ptr_length,
  338. pbool escape, pbool w_one, pbool w_many,
  339. size_t res_length,
  340. char *min_str, char *max_str,
  341. size_t *min_length, size_t *max_length);
  342. my_bool my_like_range_ucs2(CHARSET_INFO *cs,
  343. const char *ptr, size_t ptr_length,
  344. pbool escape, pbool w_one, pbool w_many,
  345. size_t res_length,
  346. char *min_str, char *max_str,
  347. size_t *min_length, size_t *max_length);
  348. int my_wildcmp_8bit(CHARSET_INFO *,
  349. const char *str,const char *str_end,
  350. const char *wildstr,const char *wildend,
  351. int escape, int w_one, int w_many);
  352. int my_wildcmp_bin(CHARSET_INFO *,
  353. const char *str,const char *str_end,
  354. const char *wildstr,const char *wildend,
  355. int escape, int w_one, int w_many);
  356. size_t my_numchars_8bit(CHARSET_INFO *, const char *b, const char *e);
  357. size_t my_numcells_8bit(CHARSET_INFO *, const char *b, const char *e);
  358. size_t my_charpos_8bit(CHARSET_INFO *, const char *b, const char *e, size_t pos);
  359. size_t my_well_formed_len_8bit(CHARSET_INFO *, const char *b, const char *e,
  360. size_t pos, int *error);
  361. uint my_mbcharlen_8bit(CHARSET_INFO *, uint c);
  362. /* Functions for multibyte charsets */
  363. extern size_t my_caseup_str_mb(CHARSET_INFO *, char *);
  364. extern size_t my_casedn_str_mb(CHARSET_INFO *, char *);
  365. extern size_t my_caseup_mb(CHARSET_INFO *, char *src, size_t srclen,
  366. char *dst, size_t dstlen);
  367. extern size_t my_casedn_mb(CHARSET_INFO *, char *src, size_t srclen,
  368. char *dst, size_t dstlen);
  369. extern int my_strcasecmp_mb(CHARSET_INFO * cs,const char *, const char *);
  370. int my_wildcmp_mb(CHARSET_INFO *,
  371. const char *str,const char *str_end,
  372. const char *wildstr,const char *wildend,
  373. int escape, int w_one, int w_many);
  374. size_t my_numchars_mb(CHARSET_INFO *, const char *b, const char *e);
  375. size_t my_numcells_mb(CHARSET_INFO *, const char *b, const char *e);
  376. size_t my_charpos_mb(CHARSET_INFO *, const char *b, const char *e, size_t pos);
  377. size_t my_well_formed_len_mb(CHARSET_INFO *, const char *b, const char *e,
  378. size_t pos, int *error);
  379. uint my_instr_mb(struct charset_info_st *,
  380. const char *b, size_t b_length,
  381. const char *s, size_t s_length,
  382. my_match_t *match, uint nmatch);
  383. int my_wildcmp_unicode(CHARSET_INFO *cs,
  384. const char *str, const char *str_end,
  385. const char *wildstr, const char *wildend,
  386. int escape, int w_one, int w_many,
  387. MY_UNICASE_INFO **weights);
  388. extern my_bool my_parse_charset_xml(const char *bug, size_t len,
  389. int (*add)(CHARSET_INFO *cs));
  390. extern char *my_strchr(CHARSET_INFO *cs, const char *str, const char *end,
  391. pchar c);
  392. my_bool my_propagate_simple(CHARSET_INFO *cs, const uchar *str, size_t len);
  393. my_bool my_propagate_complex(CHARSET_INFO *cs, const uchar *str, size_t len);
  394. uint my_string_repertoire(CHARSET_INFO *cs, const char *str, ulong len);
  395. my_bool my_charset_is_ascii_based(CHARSET_INFO *cs);
  396. my_bool my_charset_is_8bit_pure_ascii(CHARSET_INFO *cs);
  397. uint my_charset_repertoire(CHARSET_INFO *cs);
  398. #define _MY_U 01 /* Upper case */
  399. #define _MY_L 02 /* Lower case */
  400. #define _MY_NMR 04 /* Numeral (digit) */
  401. #define _MY_SPC 010 /* Spacing character */
  402. #define _MY_PNT 020 /* Punctuation */
  403. #define _MY_CTR 040 /* Control character */
  404. #define _MY_B 0100 /* Blank */
  405. #define _MY_X 0200 /* heXadecimal digit */
  406. #define my_isascii(c) (!((c) & ~0177))
  407. #define my_toascii(c) ((c) & 0177)
  408. #define my_tocntrl(c) ((c) & 31)
  409. #define my_toprint(c) ((c) | 64)
  410. #define my_toupper(s,c) (char) ((s)->to_upper[(uchar) (c)])
  411. #define my_tolower(s,c) (char) ((s)->to_lower[(uchar) (c)])
  412. #define my_isalpha(s, c) (((s)->ctype+1)[(uchar) (c)] & (_MY_U | _MY_L))
  413. #define my_isupper(s, c) (((s)->ctype+1)[(uchar) (c)] & _MY_U)
  414. #define my_islower(s, c) (((s)->ctype+1)[(uchar) (c)] & _MY_L)
  415. #define my_isdigit(s, c) (((s)->ctype+1)[(uchar) (c)] & _MY_NMR)
  416. #define my_isxdigit(s, c) (((s)->ctype+1)[(uchar) (c)] & _MY_X)
  417. #define my_isalnum(s, c) (((s)->ctype+1)[(uchar) (c)] & (_MY_U | _MY_L | _MY_NMR))
  418. #define my_isspace(s, c) (((s)->ctype+1)[(uchar) (c)] & _MY_SPC)
  419. #define my_ispunct(s, c) (((s)->ctype+1)[(uchar) (c)] & _MY_PNT)
  420. #define my_isprint(s, c) (((s)->ctype+1)[(uchar) (c)] & (_MY_PNT | _MY_U | _MY_L | _MY_NMR | _MY_B))
  421. #define my_isgraph(s, c) (((s)->ctype+1)[(uchar) (c)] & (_MY_PNT | _MY_U | _MY_L | _MY_NMR))
  422. #define my_iscntrl(s, c) (((s)->ctype+1)[(uchar) (c)] & _MY_CTR)
  423. /* Some macros that should be cleaned up a little */
  424. #define my_isvar(s,c) (my_isalnum(s,c) || (c) == '_')
  425. #define my_isvar_start(s,c) (my_isalpha(s,c) || (c) == '_')
  426. #define my_binary_compare(s) ((s)->state & MY_CS_BINSORT)
  427. #define use_strnxfrm(s) ((s)->state & MY_CS_STRNXFRM)
  428. #define my_strnxfrm(s, a, b, c, d) ((s)->coll->strnxfrm((s), (a), (b), (c), (d)))
  429. #define my_strnncoll(s, a, b, c, d) ((s)->coll->strnncoll((s), (a), (b), (c), (d), 0))
  430. #define my_like_range(s, a, b, c, d, e, f, g, h, i, j) \
  431. ((s)->coll->like_range((s), (a), (b), (c), (d), (e), (f), (g), (h), (i), (j)))
  432. #define my_wildcmp(cs,s,se,w,we,e,o,m) ((cs)->coll->wildcmp((cs),(s),(se),(w),(we),(e),(o),(m)))
  433. #define my_strcasecmp(s, a, b) ((s)->coll->strcasecmp((s), (a), (b)))
  434. #define my_charpos(cs, b, e, num) (cs)->cset->charpos((cs), (const char*) (b), (const char *)(e), (num))
  435. #define use_mb(s) ((s)->cset->ismbchar != NULL)
  436. #define my_ismbchar(s, a, b) ((s)->cset->ismbchar((s), (a), (b)))
  437. #ifdef USE_MB
  438. #define my_mbcharlen(s, a) ((s)->cset->mbcharlen((s),(a)))
  439. #else
  440. #define my_mbcharlen(s, a) 1
  441. #endif
  442. #define my_caseup_str(s, a) ((s)->cset->caseup_str((s), (a)))
  443. #define my_casedn_str(s, a) ((s)->cset->casedn_str((s), (a)))
  444. #define my_strntol(s, a, b, c, d, e) ((s)->cset->strntol((s),(a),(b),(c),(d),(e)))
  445. #define my_strntoul(s, a, b, c, d, e) ((s)->cset->strntoul((s),(a),(b),(c),(d),(e)))
  446. #define my_strntoll(s, a, b, c, d, e) ((s)->cset->strntoll((s),(a),(b),(c),(d),(e)))
  447. #define my_strntoull(s, a, b, c,d, e) ((s)->cset->strntoull((s),(a),(b),(c),(d),(e)))
  448. #define my_strntod(s, a, b, c, d) ((s)->cset->strntod((s),(a),(b),(c),(d)))
  449. /* XXX: still need to take care of this one */
  450. #ifdef MY_CHARSET_TIS620
  451. #error The TIS620 charset is broken at the moment. Tell tim to fix it.
  452. #define USE_TIS620
  453. #include "t_ctype.h"
  454. #endif
  455. #ifdef __cplusplus
  456. }
  457. #endif
  458. #endif /* _m_ctype_h */