m_ctype.h 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
  1. /* Copyright (c) 2000, 2013, Oracle and/or its affiliates.
  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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  12. /*
  13. A better inplementation of the UNIX ctype(3) library.
  14. */
  15. #ifndef _m_ctype_h
  16. #define _m_ctype_h
  17. #include <my_attribute.h>
  18. #include "my_global.h" /* uint16, uchar */
  19. enum loglevel {
  20. ERROR_LEVEL= 0,
  21. WARNING_LEVEL= 1,
  22. INFORMATION_LEVEL= 2
  23. };
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #define MY_CS_NAME_SIZE 32
  28. #define MY_CS_CTYPE_TABLE_SIZE 257
  29. #define MY_CS_TO_LOWER_TABLE_SIZE 256
  30. #define MY_CS_TO_UPPER_TABLE_SIZE 256
  31. #define MY_CS_SORT_ORDER_TABLE_SIZE 256
  32. #define MY_CS_TO_UNI_TABLE_SIZE 256
  33. #define CHARSET_DIR "charsets/"
  34. #define my_wc_t ulong
  35. #define MY_CS_REPLACEMENT_CHARACTER 0xFFFD
  36. /*
  37. On i386 we store Unicode->CS conversion tables for
  38. some character sets using Big-endian order,
  39. to copy two bytes at onces.
  40. This gives some performance improvement.
  41. */
  42. #ifdef __i386__
  43. #define MB2(x) (((x) >> 8) + (((x) & 0xFF) << 8))
  44. #define MY_PUT_MB2(s, code) { *((uint16*)(s))= (code); }
  45. #else
  46. #define MB2(x) (x)
  47. #define MY_PUT_MB2(s, code) { (s)[0]= code >> 8; (s)[1]= code & 0xFF; }
  48. #endif
  49. typedef const struct my_charset_handler_st MY_CHARSET_HANDLER;
  50. typedef const struct my_collation_handler_st MY_COLLATION_HANDLER;
  51. typedef const struct unicase_info_st MY_UNICASE_INFO;
  52. typedef const struct uni_ctype_st MY_UNI_CTYPE;
  53. typedef const struct my_uni_idx_st MY_UNI_IDX;
  54. typedef struct unicase_info_char_st
  55. {
  56. uint32 toupper;
  57. uint32 tolower;
  58. uint32 sort;
  59. } MY_UNICASE_CHARACTER;
  60. struct unicase_info_st
  61. {
  62. my_wc_t maxchar;
  63. MY_UNICASE_CHARACTER **page;
  64. };
  65. extern MY_UNICASE_INFO my_unicase_default;
  66. extern MY_UNICASE_INFO my_unicase_turkish;
  67. extern MY_UNICASE_INFO my_unicase_mysql500;
  68. extern MY_UNICASE_INFO my_unicase_unicode520;
  69. #define MY_UCA_MAX_CONTRACTION 6
  70. /*
  71. The DUCET tables in ctype-uca.c are dumped with a limit of 8 weights
  72. per character. cs->strxfrm_multiply is set to 8 for all UCA based collations.
  73. In language-specific UCA collations (with tailorings) we also do not allow
  74. a single character to have more than 8 weights to stay with the same
  75. strxfrm_multiply limit. Note, contractions are allowed to have twice longer
  76. weight strings (up to 16 weights). As a contraction consists of at
  77. least 2 characters, this makes sure that strxfrm_multiply ratio of 8
  78. is respected.
  79. */
  80. #define MY_UCA_MAX_WEIGHT_SIZE (8+1) /* Including 0 terminator */
  81. #define MY_UCA_CONTRACTION_MAX_WEIGHT_SIZE (2*8+1) /* Including 0 terminator */
  82. #define MY_UCA_WEIGHT_LEVELS 2
  83. typedef struct my_contraction_t
  84. {
  85. my_wc_t ch[MY_UCA_MAX_CONTRACTION]; /* Character sequence */
  86. uint16 weight[MY_UCA_CONTRACTION_MAX_WEIGHT_SIZE];/* Its weight string, 0-terminated */
  87. my_bool with_context;
  88. } MY_CONTRACTION;
  89. typedef struct my_contraction_list_t
  90. {
  91. size_t nitems; /* Number of items in the list */
  92. MY_CONTRACTION *item; /* List of contractions */
  93. char *flags; /* Character flags, e.g. "is contraction head") */
  94. } MY_CONTRACTIONS;
  95. my_bool my_uca_can_be_contraction_head(const MY_CONTRACTIONS *c, my_wc_t wc);
  96. my_bool my_uca_can_be_contraction_tail(const MY_CONTRACTIONS *c, my_wc_t wc);
  97. uint16 *my_uca_contraction2_weight(const MY_CONTRACTIONS *c,
  98. my_wc_t wc1, my_wc_t wc2);
  99. /* Collation weights on a single level (e.g. primary, secondary, tertiarty) */
  100. typedef struct my_uca_level_info_st
  101. {
  102. my_wc_t maxchar;
  103. uchar *lengths;
  104. uint16 **weights;
  105. MY_CONTRACTIONS contractions;
  106. uint levelno;
  107. } MY_UCA_WEIGHT_LEVEL;
  108. typedef struct uca_info_st
  109. {
  110. MY_UCA_WEIGHT_LEVEL level[MY_UCA_WEIGHT_LEVELS];
  111. /* Logical positions */
  112. my_wc_t first_non_ignorable;
  113. my_wc_t last_non_ignorable;
  114. my_wc_t first_primary_ignorable;
  115. my_wc_t last_primary_ignorable;
  116. my_wc_t first_secondary_ignorable;
  117. my_wc_t last_secondary_ignorable;
  118. my_wc_t first_tertiary_ignorable;
  119. my_wc_t last_tertiary_ignorable;
  120. my_wc_t first_trailing;
  121. my_wc_t last_trailing;
  122. my_wc_t first_variable;
  123. my_wc_t last_variable;
  124. } MY_UCA_INFO;
  125. extern MY_UCA_INFO my_uca_v400;
  126. struct uni_ctype_st
  127. {
  128. uchar pctype;
  129. const uchar *ctype;
  130. };
  131. extern MY_UNI_CTYPE my_uni_ctype[256];
  132. /* wm_wc and wc_mb return codes */
  133. #define MY_CS_ILSEQ 0 /* Wrong by sequence: wb_wc */
  134. #define MY_CS_ILUNI 0 /* Cannot encode Unicode to charset: wc_mb */
  135. #define MY_CS_TOOSMALL -101 /* Need at least one byte: wc_mb and mb_wc */
  136. #define MY_CS_TOOSMALL2 -102 /* Need at least two bytes: wc_mb and mb_wc */
  137. #define MY_CS_TOOSMALL3 -103 /* Need at least three bytes: wc_mb and mb_wc */
  138. /* These following three are currently not really used */
  139. #define MY_CS_TOOSMALL4 -104 /* Need at least 4 bytes: wc_mb and mb_wc */
  140. #define MY_CS_TOOSMALL5 -105 /* Need at least 5 bytes: wc_mb and mb_wc */
  141. #define MY_CS_TOOSMALL6 -106 /* Need at least 6 bytes: wc_mb and mb_wc */
  142. /* A helper macros for "need at least n bytes" */
  143. #define MY_CS_TOOSMALLN(n) (-100-(n))
  144. #define MY_SEQ_INTTAIL 1
  145. #define MY_SEQ_SPACES 2
  146. /* My charsets_list flags */
  147. #define MY_CS_COMPILED 1 /* compiled-in sets */
  148. #define MY_CS_CONFIG 2 /* sets that have a *.conf file */
  149. #define MY_CS_INDEX 4 /* sets listed in the Index file */
  150. #define MY_CS_LOADED 8 /* sets that are currently loaded */
  151. #define MY_CS_BINSORT 16 /* if binary sort order */
  152. #define MY_CS_PRIMARY 32 /* if primary collation */
  153. #define MY_CS_STRNXFRM 64 /* if strnxfrm is used for sort */
  154. #define MY_CS_UNICODE 128 /* is a charset is BMP Unicode */
  155. #define MY_CS_READY 256 /* if a charset is initialized */
  156. #define MY_CS_AVAILABLE 512 /* If either compiled-in or loaded*/
  157. #define MY_CS_CSSORT 1024 /* if case sensitive sort order */
  158. #define MY_CS_HIDDEN 2048 /* don't display in SHOW */
  159. #define MY_CS_PUREASCII 4096 /* if a charset is pure ascii */
  160. #define MY_CS_NONASCII 8192 /* if not ASCII-compatible */
  161. #define MY_CS_UNICODE_SUPPLEMENT 16384 /* Non-BMP Unicode characters */
  162. #define MY_CS_LOWER_SORT 32768 /* If use lower case as weight */
  163. #define MY_CS_STRNXFRM_BAD_NWEIGHTS 0x10000 /* strnxfrm ignores "nweights" */
  164. #define MY_CS_NOPAD 0x20000 /* if does not ignore trailing spaces */
  165. #define MY_CS_NON1TO1 0x40000 /* Has a complex mapping from characters
  166. to weights, e.g. contractions, expansions,
  167. ignorable characters */
  168. #define MY_CHARSET_UNDEFINED 0
  169. /* Character repertoire flags */
  170. #define MY_REPERTOIRE_ASCII 1 /* Pure ASCII U+0000..U+007F */
  171. #define MY_REPERTOIRE_EXTENDED 2 /* Extended characters: U+0080..U+FFFF */
  172. #define MY_REPERTOIRE_UNICODE30 3 /* ASCII | EXTENDED: U+0000..U+FFFF */
  173. /* Flags for strxfrm */
  174. #define MY_STRXFRM_LEVEL1 0x00000001 /* for primary weights */
  175. #define MY_STRXFRM_LEVEL2 0x00000002 /* for secondary weights */
  176. #define MY_STRXFRM_LEVEL3 0x00000004 /* for tertiary weights */
  177. #define MY_STRXFRM_LEVEL4 0x00000008 /* fourth level weights */
  178. #define MY_STRXFRM_LEVEL5 0x00000010 /* fifth level weights */
  179. #define MY_STRXFRM_LEVEL6 0x00000020 /* sixth level weights */
  180. #define MY_STRXFRM_LEVEL_ALL 0x0000003F /* Bit OR for the above six */
  181. #define MY_STRXFRM_NLEVELS 6 /* Number of possible levels*/
  182. #define MY_STRXFRM_PAD_WITH_SPACE 0x00000040 /* if pad result with spaces */
  183. #define MY_STRXFRM_PAD_TO_MAXLEN 0x00000080 /* if pad tail(for filesort) */
  184. #define MY_STRXFRM_DESC_LEVEL1 0x00000100 /* if desc order for level1 */
  185. #define MY_STRXFRM_DESC_LEVEL2 0x00000200 /* if desc order for level2 */
  186. #define MY_STRXFRM_DESC_LEVEL3 0x00000300 /* if desc order for level3 */
  187. #define MY_STRXFRM_DESC_LEVEL4 0x00000800 /* if desc order for level4 */
  188. #define MY_STRXFRM_DESC_LEVEL5 0x00001000 /* if desc order for level5 */
  189. #define MY_STRXFRM_DESC_LEVEL6 0x00002000 /* if desc order for level6 */
  190. #define MY_STRXFRM_DESC_SHIFT 8
  191. #define MY_STRXFRM_UNUSED_00004000 0x00004000 /* for future extensions */
  192. #define MY_STRXFRM_UNUSED_00008000 0x00008000 /* for future extensions */
  193. #define MY_STRXFRM_REVERSE_LEVEL1 0x00010000 /* if reverse order for level1 */
  194. #define MY_STRXFRM_REVERSE_LEVEL2 0x00020000 /* if reverse order for level2 */
  195. #define MY_STRXFRM_REVERSE_LEVEL3 0x00040000 /* if reverse order for level3 */
  196. #define MY_STRXFRM_REVERSE_LEVEL4 0x00080000 /* if reverse order for level4 */
  197. #define MY_STRXFRM_REVERSE_LEVEL5 0x00100000 /* if reverse order for level5 */
  198. #define MY_STRXFRM_REVERSE_LEVEL6 0x00200000 /* if reverse order for level6 */
  199. #define MY_STRXFRM_REVERSE_SHIFT 16
  200. /*
  201. Collation IDs for MariaDB that should not conflict with MySQL.
  202. We reserve 256..511, because MySQL will most likely use this range
  203. when the range 0..255 is full.
  204. We use the next 256 IDs starting from 512 and divide
  205. them into 8 chunks, 32 collations each, as follows:
  206. 512 + (0..31) for single byte collations (e.g. latin9)
  207. 512 + (32..63) reserved (e.g. for utf32le, or more single byte collations)
  208. 512 + (64..95) for utf8
  209. 512 + (96..127) for utf8mb4
  210. 512 + (128..159) for ucs2
  211. 512 + (160..192) for utf16
  212. 512 + (192..223) for utf16le
  213. 512 + (224..255) for utf32
  214. */
  215. #define MY_PAGE2_COLLATION_ID_8BIT 0x200
  216. #define MY_PAGE2_COLLATION_ID_RESERVED 0x220
  217. #define MY_PAGE2_COLLATION_ID_UTF8 0x240
  218. #define MY_PAGE2_COLLATION_ID_UTF8MB4 0x260
  219. #define MY_PAGE2_COLLATION_ID_UCS2 0x280
  220. #define MY_PAGE2_COLLATION_ID_UTF16 0x2A0
  221. #define MY_PAGE2_COLLATION_ID_UTF16LE 0x2C0
  222. #define MY_PAGE2_COLLATION_ID_UTF32 0x2E0
  223. struct my_uni_idx_st
  224. {
  225. uint16 from;
  226. uint16 to;
  227. const uchar *tab;
  228. };
  229. typedef struct
  230. {
  231. uint beg;
  232. uint end;
  233. uint mb_len;
  234. } my_match_t;
  235. enum my_lex_states
  236. {
  237. MY_LEX_START, MY_LEX_CHAR, MY_LEX_IDENT,
  238. MY_LEX_IDENT_SEP, MY_LEX_IDENT_START,
  239. MY_LEX_REAL, MY_LEX_HEX_NUMBER, MY_LEX_BIN_NUMBER,
  240. MY_LEX_CMP_OP, MY_LEX_LONG_CMP_OP, MY_LEX_STRING, MY_LEX_COMMENT, MY_LEX_END,
  241. MY_LEX_OPERATOR_OR_IDENT, MY_LEX_NUMBER_IDENT, MY_LEX_INT_OR_REAL,
  242. MY_LEX_REAL_OR_POINT, MY_LEX_BOOL, MY_LEX_EOL, MY_LEX_ESCAPE,
  243. MY_LEX_LONG_COMMENT, MY_LEX_END_LONG_COMMENT, MY_LEX_SEMICOLON,
  244. MY_LEX_SET_VAR, MY_LEX_USER_END, MY_LEX_HOSTNAME, MY_LEX_SKIP,
  245. MY_LEX_USER_VARIABLE_DELIMITER, MY_LEX_SYSTEM_VAR,
  246. MY_LEX_IDENT_OR_KEYWORD,
  247. MY_LEX_IDENT_OR_HEX, MY_LEX_IDENT_OR_BIN, MY_LEX_IDENT_OR_NCHAR,
  248. MY_LEX_STRING_OR_DELIMITER, MY_LEX_MINUS_OR_COMMENT, MY_LEX_PLACEHOLDER,
  249. MY_LEX_COMMA
  250. };
  251. struct charset_info_st;
  252. typedef struct my_charset_loader_st
  253. {
  254. char error[128];
  255. void *(*once_alloc)(size_t);
  256. void *(*malloc)(size_t);
  257. void *(*realloc)(void *, size_t);
  258. void (*free)(void *);
  259. void (*reporter)(enum loglevel, const char *format, ...);
  260. int (*add_collation)(struct charset_info_st *cs);
  261. } MY_CHARSET_LOADER;
  262. extern int (*my_string_stack_guard)(int);
  263. /* See strings/CHARSET_INFO.txt for information about this structure */
  264. struct my_collation_handler_st
  265. {
  266. my_bool (*init)(struct charset_info_st *, MY_CHARSET_LOADER *);
  267. /* Collation routines */
  268. int (*strnncoll)(CHARSET_INFO *,
  269. const uchar *, size_t, const uchar *, size_t, my_bool);
  270. int (*strnncollsp)(CHARSET_INFO *,
  271. const uchar *, size_t, const uchar *, size_t,
  272. my_bool diff_if_only_endspace_difference);
  273. size_t (*strnxfrm)(CHARSET_INFO *,
  274. uchar *dst, size_t dstlen, uint nweights,
  275. const uchar *src, size_t srclen, uint flags);
  276. size_t (*strnxfrmlen)(CHARSET_INFO *, size_t);
  277. my_bool (*like_range)(CHARSET_INFO *,
  278. const char *s, size_t s_length,
  279. pchar w_prefix, pchar w_one, pchar w_many,
  280. size_t res_length,
  281. char *min_str, char *max_str,
  282. size_t *min_len, size_t *max_len);
  283. int (*wildcmp)(CHARSET_INFO *,
  284. const char *str,const char *str_end,
  285. const char *wildstr,const char *wildend,
  286. int escape,int w_one, int w_many);
  287. int (*strcasecmp)(CHARSET_INFO *, const char *, const char *);
  288. uint (*instr)(CHARSET_INFO *,
  289. const char *b, size_t b_length,
  290. const char *s, size_t s_length,
  291. my_match_t *match, uint nmatch);
  292. /* Hash calculation */
  293. void (*hash_sort)(CHARSET_INFO *cs, const uchar *key, size_t len,
  294. ulong *nr1, ulong *nr2);
  295. my_bool (*propagate)(CHARSET_INFO *cs, const uchar *str, size_t len);
  296. };
  297. extern MY_COLLATION_HANDLER my_collation_8bit_bin_handler;
  298. extern MY_COLLATION_HANDLER my_collation_8bit_simple_ci_handler;
  299. extern MY_COLLATION_HANDLER my_collation_ucs2_uca_handler;
  300. /* Some typedef to make it easy for C++ to make function pointers */
  301. typedef int (*my_charset_conv_mb_wc)(CHARSET_INFO *, my_wc_t *,
  302. const uchar *, const uchar *);
  303. typedef int (*my_charset_conv_wc_mb)(CHARSET_INFO *, my_wc_t,
  304. uchar *, uchar *);
  305. typedef size_t (*my_charset_conv_case)(CHARSET_INFO *,
  306. char *, size_t, char *, size_t);
  307. /*
  308. A structure to return the statistics of a native string copying,
  309. when no Unicode conversion is involved.
  310. The stucture is OK to be unitialized before calling a copying routine.
  311. A copying routine must populate the structure as follows:
  312. - m_source_end_pos must be set by to a non-NULL value
  313. in the range of the input string.
  314. - m_well_formed_error_pos must be set to NULL if the string was
  315. well formed, or to the position of the leftmost bad byte sequence.
  316. */
  317. typedef struct
  318. {
  319. const char *m_source_end_pos; /* Position where reading stopped */
  320. const char *m_well_formed_error_pos; /* Position where a bad byte was found*/
  321. } MY_STRCOPY_STATUS;
  322. /*
  323. A structure to return the statistics of a Unicode string conversion.
  324. */
  325. typedef struct
  326. {
  327. MY_STRCOPY_STATUS m_native_copy_status;
  328. const char *m_cannot_convert_error_pos;
  329. } MY_STRCONV_STATUS;
  330. /* See strings/CHARSET_INFO.txt about information on this structure */
  331. struct my_charset_handler_st
  332. {
  333. my_bool (*init)(struct charset_info_st *, MY_CHARSET_LOADER *loader);
  334. /* Multibyte routines */
  335. uint (*ismbchar)(CHARSET_INFO *, const char *, const char *);
  336. uint (*mbcharlen)(CHARSET_INFO *, uint c);
  337. size_t (*numchars)(CHARSET_INFO *, const char *b, const char *e);
  338. size_t (*charpos)(CHARSET_INFO *, const char *b, const char *e,
  339. size_t pos);
  340. size_t (*well_formed_len)(CHARSET_INFO *,
  341. const char *b,const char *e,
  342. size_t nchars, int *error);
  343. size_t (*lengthsp)(CHARSET_INFO *, const char *ptr, size_t length);
  344. size_t (*numcells)(CHARSET_INFO *, const char *b, const char *e);
  345. /* Unicode conversion */
  346. my_charset_conv_mb_wc mb_wc;
  347. my_charset_conv_wc_mb wc_mb;
  348. /* CTYPE scanner */
  349. int (*ctype)(CHARSET_INFO *cs, int *ctype,
  350. const uchar *s, const uchar *e);
  351. /* Functions for case and sort conversion */
  352. size_t (*caseup_str)(CHARSET_INFO *, char *);
  353. size_t (*casedn_str)(CHARSET_INFO *, char *);
  354. my_charset_conv_case caseup;
  355. my_charset_conv_case casedn;
  356. /* Charset dependant snprintf() */
  357. size_t (*snprintf)(CHARSET_INFO *, char *to, size_t n,
  358. const char *fmt,
  359. ...) ATTRIBUTE_FORMAT_FPTR(printf, 4, 5);
  360. size_t (*long10_to_str)(CHARSET_INFO *, char *to, size_t n,
  361. int radix, long int val);
  362. size_t (*longlong10_to_str)(CHARSET_INFO *, char *to, size_t n,
  363. int radix, longlong val);
  364. void (*fill)(CHARSET_INFO *, char *to, size_t len, int fill);
  365. /* String-to-number conversion routines */
  366. long (*strntol)(CHARSET_INFO *, const char *s, size_t l,
  367. int base, char **e, int *err);
  368. ulong (*strntoul)(CHARSET_INFO *, const char *s, size_t l,
  369. int base, char **e, int *err);
  370. longlong (*strntoll)(CHARSET_INFO *, const char *s, size_t l,
  371. int base, char **e, int *err);
  372. ulonglong (*strntoull)(CHARSET_INFO *, const char *s, size_t l,
  373. int base, char **e, int *err);
  374. double (*strntod)(CHARSET_INFO *, char *s, size_t l, char **e,
  375. int *err);
  376. longlong (*strtoll10)(CHARSET_INFO *cs,
  377. const char *nptr, char **endptr, int *error);
  378. ulonglong (*strntoull10rnd)(CHARSET_INFO *cs,
  379. const char *str, size_t length,
  380. int unsigned_fl,
  381. char **endptr, int *error);
  382. size_t (*scan)(CHARSET_INFO *, const char *b, const char *e,
  383. int sq);
  384. /* String copying routines and helpers for them */
  385. /*
  386. charlen() - calculate length of the left-most character in bytes.
  387. @param cs Character set
  388. @param str The beginning of the string
  389. @param end The end of the string
  390. @return MY_CS_ILSEQ if a bad byte sequence was found.
  391. @return MY_CS_TOOSMALLN(x) if the string ended unexpectedly.
  392. @return a positive number in the range 1..mbmaxlen,
  393. if a valid character was found.
  394. */
  395. int (*charlen)(CHARSET_INFO *cs, const uchar *str, const uchar *end);
  396. /*
  397. well_formed_char_length() - returns character length of a string.
  398. @param cs Character set
  399. @param str The beginning of the string
  400. @param end The end of the string
  401. @param nchars Not more than "nchars" left-most characters are checked.
  402. @param status[OUT] Additional statistics is returned here.
  403. "status" can be uninitialized before the call,
  404. and it is fully initialized after the call.
  405. status->m_source_end_pos is set to the position where reading stopped.
  406. If a bad byte sequence is found, the function returns immediately and
  407. status->m_well_formed_error_pos is set to the position where a bad byte
  408. sequence was found.
  409. status->m_well_formed_error_pos is set to NULL if no bad bytes were found.
  410. If status->m_well_formed_error_pos is NULL after the call, that means:
  411. - either the function reached the end of the string,
  412. - or all "nchars" characters were read.
  413. The caller can check status->m_source_end_pos to detect which of these two
  414. happened.
  415. */
  416. size_t (*well_formed_char_length)(CHARSET_INFO *cs,
  417. const char *str, const char *end,
  418. size_t nchars,
  419. MY_STRCOPY_STATUS *status);
  420. /*
  421. copy_fix() - copy a string, replace bad bytes to '?'.
  422. Not more than "nchars" characters are copied.
  423. status->m_source_end_pos is set to a position in the range
  424. between "src" and "src + src_length", where reading stopped.
  425. status->m_well_formed_error_pos is set to NULL if the string
  426. in the range "src" and "status->m_source_end_pos" was well formed,
  427. or is set to a position between "src" and "src + src_length" where
  428. the leftmost bad byte sequence was found.
  429. */
  430. size_t (*copy_fix)(CHARSET_INFO *,
  431. char *dst, size_t dst_length,
  432. const char *src, size_t src_length,
  433. size_t nchars, MY_STRCOPY_STATUS *status);
  434. /**
  435. Write a character to the target string, using its native code.
  436. For Unicode character sets (utf8, ucs2, utf16, utf16le, utf32, filename)
  437. native codes are equvalent to Unicode code points.
  438. For 8bit character sets the native code is just the byte value.
  439. For Asian characters sets:
  440. - MB1 native code is just the byte value (e.g. on the ASCII range)
  441. - MB2 native code is ((b0 << 8) + b1).
  442. - MB3 native code is ((b0 <<16) + (b1 << 8) + b2)
  443. Note, CHARSET_INFO::min_sort_char and CHARSET_INFO::max_sort_char
  444. are defined in native notation and should be written using
  445. cs->cset->native_to_mb() rather than cs->cset->wc_mb().
  446. */
  447. my_charset_conv_wc_mb native_to_mb;
  448. };
  449. extern MY_CHARSET_HANDLER my_charset_8bit_handler;
  450. extern MY_CHARSET_HANDLER my_charset_ucs2_handler;
  451. extern MY_CHARSET_HANDLER my_charset_utf8_handler;
  452. /*
  453. We define this CHARSET_INFO_DEFINED here to prevent a repeat of the
  454. typedef in hash.c, which will cause a compiler error.
  455. */
  456. #define CHARSET_INFO_DEFINED
  457. /* See strings/CHARSET_INFO.txt about information on this structure */
  458. struct charset_info_st
  459. {
  460. uint number;
  461. uint primary_number;
  462. uint binary_number;
  463. uint state;
  464. const char *csname;
  465. const char *name;
  466. const char *comment;
  467. const char *tailoring;
  468. const uchar *ctype;
  469. const uchar *to_lower;
  470. const uchar *to_upper;
  471. const uchar *sort_order;
  472. MY_UCA_INFO *uca;
  473. const uint16 *tab_to_uni;
  474. MY_UNI_IDX *tab_from_uni;
  475. MY_UNICASE_INFO *caseinfo;
  476. const uchar *state_map;
  477. const uchar *ident_map;
  478. uint strxfrm_multiply;
  479. uchar caseup_multiply;
  480. uchar casedn_multiply;
  481. uint mbminlen;
  482. uint mbmaxlen;
  483. my_wc_t min_sort_char;
  484. my_wc_t max_sort_char; /* For LIKE optimization */
  485. uchar pad_char;
  486. my_bool escape_with_backslash_is_dangerous;
  487. uchar levels_for_order;
  488. MY_CHARSET_HANDLER *cset;
  489. MY_COLLATION_HANDLER *coll;
  490. };
  491. #define ILLEGAL_CHARSET_INFO_NUMBER (~0U)
  492. extern MYSQL_PLUGIN_IMPORT struct charset_info_st my_charset_bin;
  493. extern MYSQL_PLUGIN_IMPORT struct charset_info_st my_charset_latin1;
  494. extern MYSQL_PLUGIN_IMPORT struct charset_info_st my_charset_filename;
  495. extern MYSQL_PLUGIN_IMPORT struct charset_info_st my_charset_utf8_general_ci;
  496. extern struct charset_info_st my_charset_big5_bin;
  497. extern struct charset_info_st my_charset_big5_chinese_ci;
  498. extern struct charset_info_st my_charset_cp1250_czech_ci;
  499. extern struct charset_info_st my_charset_cp932_bin;
  500. extern struct charset_info_st my_charset_cp932_japanese_ci;
  501. extern struct charset_info_st my_charset_eucjpms_bin;
  502. extern struct charset_info_st my_charset_eucjpms_japanese_ci;
  503. extern struct charset_info_st my_charset_euckr_bin;
  504. extern struct charset_info_st my_charset_euckr_korean_ci;
  505. extern struct charset_info_st my_charset_gb2312_bin;
  506. extern struct charset_info_st my_charset_gb2312_chinese_ci;
  507. extern struct charset_info_st my_charset_gbk_bin;
  508. extern struct charset_info_st my_charset_gbk_chinese_ci;
  509. extern struct charset_info_st my_charset_latin1_bin;
  510. extern struct charset_info_st my_charset_latin1_german2_ci;
  511. extern struct charset_info_st my_charset_latin2_czech_ci;
  512. extern struct charset_info_st my_charset_sjis_bin;
  513. extern struct charset_info_st my_charset_sjis_japanese_ci;
  514. extern struct charset_info_st my_charset_tis620_bin;
  515. extern struct charset_info_st my_charset_tis620_thai_ci;
  516. extern struct charset_info_st my_charset_ucs2_bin;
  517. extern struct charset_info_st my_charset_ucs2_general_ci;
  518. extern struct charset_info_st my_charset_ucs2_general_mysql500_ci;
  519. extern struct charset_info_st my_charset_ucs2_unicode_ci;
  520. extern struct charset_info_st my_charset_ucs2_general_mysql500_ci;
  521. extern struct charset_info_st my_charset_ujis_bin;
  522. extern struct charset_info_st my_charset_ujis_japanese_ci;
  523. extern struct charset_info_st my_charset_utf16_bin;
  524. extern struct charset_info_st my_charset_utf16_general_ci;
  525. extern struct charset_info_st my_charset_utf16_unicode_ci;
  526. extern struct charset_info_st my_charset_utf16le_bin;
  527. extern struct charset_info_st my_charset_utf16le_general_ci;
  528. extern struct charset_info_st my_charset_utf32_bin;
  529. extern struct charset_info_st my_charset_utf32_general_ci;
  530. extern struct charset_info_st my_charset_utf32_unicode_ci;
  531. extern struct charset_info_st my_charset_utf8_bin;
  532. extern struct charset_info_st my_charset_utf8_general_mysql500_ci;
  533. extern struct charset_info_st my_charset_utf8_unicode_ci;
  534. extern struct charset_info_st my_charset_utf8mb4_bin;
  535. extern struct charset_info_st my_charset_utf8mb4_general_ci;
  536. extern struct charset_info_st my_charset_utf8mb4_unicode_ci;
  537. #define MY_UTF8MB3 "utf8"
  538. #define MY_UTF8MB4 "utf8mb4"
  539. my_bool my_cs_have_contractions(CHARSET_INFO *cs);
  540. my_bool my_cs_can_be_contraction_head(CHARSET_INFO *cs, my_wc_t wc);
  541. my_bool my_cs_can_be_contraction_tail(CHARSET_INFO *cs, my_wc_t wc);
  542. const uint16 *my_cs_contraction2_weight(CHARSET_INFO *cs, my_wc_t wc1,
  543. my_wc_t wc2);
  544. /* declarations for simple charsets */
  545. extern size_t my_strnxfrm_simple(CHARSET_INFO *,
  546. uchar *dst, size_t dstlen, uint nweights,
  547. const uchar *src, size_t srclen, uint flags);
  548. size_t my_strnxfrmlen_simple(CHARSET_INFO *, size_t);
  549. extern int my_strnncoll_simple(CHARSET_INFO *, const uchar *, size_t,
  550. const uchar *, size_t, my_bool);
  551. extern int my_strnncollsp_simple(CHARSET_INFO *, const uchar *, size_t,
  552. const uchar *, size_t,
  553. my_bool diff_if_only_endspace_difference);
  554. extern void my_hash_sort_simple(CHARSET_INFO *cs,
  555. const uchar *key, size_t len,
  556. ulong *nr1, ulong *nr2);
  557. extern void my_hash_sort_bin(CHARSET_INFO *cs,
  558. const uchar *key, size_t len, ulong *nr1,
  559. ulong *nr2);
  560. extern size_t my_lengthsp_8bit(CHARSET_INFO *cs, const char *ptr, size_t length);
  561. extern uint my_instr_simple(CHARSET_INFO *,
  562. const char *b, size_t b_length,
  563. const char *s, size_t s_length,
  564. my_match_t *match, uint nmatch);
  565. size_t my_copy_8bit(CHARSET_INFO *,
  566. char *dst, size_t dst_length,
  567. const char *src, size_t src_length,
  568. size_t nchars, MY_STRCOPY_STATUS *);
  569. size_t my_copy_fix_mb(CHARSET_INFO *cs,
  570. char *dst, size_t dst_length,
  571. const char *src, size_t src_length,
  572. size_t nchars, MY_STRCOPY_STATUS *);
  573. /* Functions for 8bit */
  574. extern size_t my_caseup_str_8bit(CHARSET_INFO *, char *);
  575. extern size_t my_casedn_str_8bit(CHARSET_INFO *, char *);
  576. extern size_t my_caseup_8bit(CHARSET_INFO *, char *src, size_t srclen,
  577. char *dst, size_t dstlen);
  578. extern size_t my_casedn_8bit(CHARSET_INFO *, char *src, size_t srclen,
  579. char *dst, size_t dstlen);
  580. extern int my_strcasecmp_8bit(CHARSET_INFO * cs, const char *, const char *);
  581. int my_mb_wc_8bit(CHARSET_INFO *cs,my_wc_t *wc, const uchar *s,const uchar *e);
  582. int my_wc_mb_8bit(CHARSET_INFO *cs,my_wc_t wc, uchar *s, uchar *e);
  583. int my_wc_mb_bin(CHARSET_INFO *cs,my_wc_t wc, uchar *s, uchar *e);
  584. int my_mb_ctype_8bit(CHARSET_INFO *,int *, const uchar *,const uchar *);
  585. int my_mb_ctype_mb(CHARSET_INFO *,int *, const uchar *,const uchar *);
  586. size_t my_scan_8bit(CHARSET_INFO *cs, const char *b, const char *e, int sq);
  587. size_t my_snprintf_8bit(CHARSET_INFO *, char *to, size_t n,
  588. const char *fmt, ...)
  589. ATTRIBUTE_FORMAT(printf, 4, 5);
  590. long my_strntol_8bit(CHARSET_INFO *, const char *s, size_t l, int base,
  591. char **e, int *err);
  592. ulong my_strntoul_8bit(CHARSET_INFO *, const char *s, size_t l, int base,
  593. char **e, int *err);
  594. longlong my_strntoll_8bit(CHARSET_INFO *, const char *s, size_t l, int base,
  595. char **e, int *err);
  596. ulonglong my_strntoull_8bit(CHARSET_INFO *, const char *s, size_t l, int base,
  597. char **e, int *err);
  598. double my_strntod_8bit(CHARSET_INFO *, char *s, size_t l,char **e,
  599. int *err);
  600. size_t my_long10_to_str_8bit(CHARSET_INFO *, char *to, size_t l, int radix,
  601. long int val);
  602. size_t my_longlong10_to_str_8bit(CHARSET_INFO *, char *to, size_t l, int radix,
  603. longlong val);
  604. longlong my_strtoll10_8bit(CHARSET_INFO *cs,
  605. const char *nptr, char **endptr, int *error);
  606. longlong my_strtoll10_ucs2(CHARSET_INFO *cs,
  607. const char *nptr, char **endptr, int *error);
  608. ulonglong my_strntoull10rnd_8bit(CHARSET_INFO *cs,
  609. const char *str, size_t length, int
  610. unsigned_fl, char **endptr, int *error);
  611. ulonglong my_strntoull10rnd_ucs2(CHARSET_INFO *cs,
  612. const char *str, size_t length,
  613. int unsigned_fl, char **endptr, int *error);
  614. void my_fill_8bit(CHARSET_INFO *cs, char* to, size_t l, int fill);
  615. /* For 8-bit character set */
  616. my_bool my_like_range_simple(CHARSET_INFO *cs,
  617. const char *ptr, size_t ptr_length,
  618. pbool escape, pbool w_one, pbool w_many,
  619. size_t res_length,
  620. char *min_str, char *max_str,
  621. size_t *min_length, size_t *max_length);
  622. /* For ASCII-based multi-byte character sets with mbminlen=1 */
  623. my_bool my_like_range_mb(CHARSET_INFO *cs,
  624. const char *ptr, size_t ptr_length,
  625. pbool escape, pbool w_one, pbool w_many,
  626. size_t res_length,
  627. char *min_str, char *max_str,
  628. size_t *min_length, size_t *max_length);
  629. /* For other character sets, with arbitrary mbminlen and mbmaxlen numbers */
  630. my_bool my_like_range_generic(CHARSET_INFO *cs,
  631. const char *ptr, size_t ptr_length,
  632. pbool escape, pbool w_one, pbool w_many,
  633. size_t res_length,
  634. char *min_str, char *max_str,
  635. size_t *min_length, size_t *max_length);
  636. int my_wildcmp_8bit(CHARSET_INFO *,
  637. const char *str,const char *str_end,
  638. const char *wildstr,const char *wildend,
  639. int escape, int w_one, int w_many);
  640. int my_wildcmp_bin(CHARSET_INFO *,
  641. const char *str,const char *str_end,
  642. const char *wildstr,const char *wildend,
  643. int escape, int w_one, int w_many);
  644. size_t my_numchars_8bit(CHARSET_INFO *, const char *b, const char *e);
  645. size_t my_numcells_8bit(CHARSET_INFO *, const char *b, const char *e);
  646. size_t my_charpos_8bit(CHARSET_INFO *, const char *b, const char *e, size_t pos);
  647. size_t my_well_formed_len_8bit(CHARSET_INFO *, const char *b, const char *e,
  648. size_t pos, int *error);
  649. size_t my_well_formed_char_length_8bit(CHARSET_INFO *cs,
  650. const char *b, const char *e,
  651. size_t nchars,
  652. MY_STRCOPY_STATUS *status);
  653. int my_charlen_8bit(CHARSET_INFO *, const uchar *str, const uchar *end);
  654. uint my_mbcharlen_8bit(CHARSET_INFO *, uint c);
  655. /* Functions for multibyte charsets */
  656. extern size_t my_caseup_str_mb(CHARSET_INFO *, char *);
  657. extern size_t my_casedn_str_mb(CHARSET_INFO *, char *);
  658. extern size_t my_caseup_mb(CHARSET_INFO *, char *src, size_t srclen,
  659. char *dst, size_t dstlen);
  660. extern size_t my_casedn_mb(CHARSET_INFO *, char *src, size_t srclen,
  661. char *dst, size_t dstlen);
  662. extern size_t my_caseup_mb_varlen(CHARSET_INFO *, char *src, size_t srclen,
  663. char *dst, size_t dstlen);
  664. extern size_t my_casedn_mb_varlen(CHARSET_INFO *, char *src, size_t srclen,
  665. char *dst, size_t dstlen);
  666. extern size_t my_caseup_ujis(CHARSET_INFO *, char *src, size_t srclen,
  667. char *dst, size_t dstlen);
  668. extern size_t my_casedn_ujis(CHARSET_INFO *, char *src, size_t srclen,
  669. char *dst, size_t dstlen);
  670. extern int my_strcasecmp_mb(CHARSET_INFO * cs,const char *, const char *);
  671. int my_wildcmp_mb(CHARSET_INFO *,
  672. const char *str,const char *str_end,
  673. const char *wildstr,const char *wildend,
  674. int escape, int w_one, int w_many);
  675. size_t my_numchars_mb(CHARSET_INFO *, const char *b, const char *e);
  676. size_t my_numcells_mb(CHARSET_INFO *, const char *b, const char *e);
  677. size_t my_charpos_mb(CHARSET_INFO *, const char *b, const char *e, size_t pos);
  678. size_t my_well_formed_len_mb(CHARSET_INFO *, const char *b, const char *e,
  679. size_t pos, int *error);
  680. uint my_instr_mb(CHARSET_INFO *,
  681. const char *b, size_t b_length,
  682. const char *s, size_t s_length,
  683. my_match_t *match, uint nmatch);
  684. int my_strnncoll_mb_bin(CHARSET_INFO * cs,
  685. const uchar *s, size_t slen,
  686. const uchar *t, size_t tlen,
  687. my_bool t_is_prefix);
  688. int my_strnncollsp_mb_bin(CHARSET_INFO *cs,
  689. const uchar *a, size_t a_length,
  690. const uchar *b, size_t b_length,
  691. my_bool diff_if_only_endspace_difference);
  692. int my_wildcmp_mb_bin(CHARSET_INFO *cs,
  693. const char *str,const char *str_end,
  694. const char *wildstr,const char *wildend,
  695. int escape, int w_one, int w_many);
  696. int my_strcasecmp_mb_bin(CHARSET_INFO * cs __attribute__((unused)),
  697. const char *s, const char *t);
  698. void my_hash_sort_mb_bin(CHARSET_INFO *cs __attribute__((unused)),
  699. const uchar *key, size_t len,ulong *nr1, ulong *nr2);
  700. size_t my_strnxfrm_mb(CHARSET_INFO *,
  701. uchar *dst, size_t dstlen, uint nweights,
  702. const uchar *src, size_t srclen, uint flags);
  703. size_t my_strnxfrm_unicode(CHARSET_INFO *,
  704. uchar *dst, size_t dstlen, uint nweights,
  705. const uchar *src, size_t srclen, uint flags);
  706. size_t my_strnxfrmlen_unicode(CHARSET_INFO *, size_t);
  707. size_t my_strnxfrm_unicode_full_bin(CHARSET_INFO *,
  708. uchar *dst, size_t dstlen, uint nweights,
  709. const uchar *src, size_t srclen, uint flags);
  710. size_t my_strnxfrmlen_unicode_full_bin(CHARSET_INFO *, size_t);
  711. int my_wildcmp_unicode(CHARSET_INFO *cs,
  712. const char *str, const char *str_end,
  713. const char *wildstr, const char *wildend,
  714. int escape, int w_one, int w_many,
  715. MY_UNICASE_INFO *weights);
  716. extern my_bool my_parse_charset_xml(MY_CHARSET_LOADER *loader,
  717. const char *buf, size_t buflen);
  718. extern char *my_strchr(CHARSET_INFO *cs, const char *str, const char *end,
  719. pchar c);
  720. extern size_t my_strcspn(CHARSET_INFO *cs, const char *str, const char *end,
  721. const char *accept);
  722. my_bool my_propagate_simple(CHARSET_INFO *cs, const uchar *str, size_t len);
  723. my_bool my_propagate_complex(CHARSET_INFO *cs, const uchar *str, size_t len);
  724. typedef struct
  725. {
  726. size_t char_length;
  727. uint repertoire;
  728. } MY_STRING_METADATA;
  729. void my_string_metadata_get(MY_STRING_METADATA *metadata,
  730. CHARSET_INFO *cs, const char *str, size_t len);
  731. uint my_string_repertoire(CHARSET_INFO *cs, const char *str, ulong len);
  732. my_bool my_charset_is_ascii_based(CHARSET_INFO *cs);
  733. my_bool my_charset_is_8bit_pure_ascii(CHARSET_INFO *cs);
  734. uint my_charset_repertoire(CHARSET_INFO *cs);
  735. uint my_strxfrm_flag_normalize(uint flags, uint nlevels);
  736. void my_strxfrm_desc_and_reverse(uchar *str, uchar *strend,
  737. uint flags, uint level);
  738. size_t my_strxfrm_pad_desc_and_reverse(CHARSET_INFO *cs,
  739. uchar *str, uchar *frmend, uchar *strend,
  740. uint nweights, uint flags, uint level);
  741. my_bool my_charset_is_ascii_compatible(CHARSET_INFO *cs);
  742. const MY_CONTRACTIONS *my_charset_get_contractions(CHARSET_INFO *cs,
  743. int level);
  744. extern size_t my_vsnprintf_ex(CHARSET_INFO *cs, char *to, size_t n,
  745. const char* fmt, va_list ap);
  746. /*
  747. Convert a string between two character sets.
  748. Bad byte sequences as well as characters that cannot be
  749. encoded in the destination character set are replaced to '?'.
  750. */
  751. uint32 my_convert(char *to, uint32 to_length, CHARSET_INFO *to_cs,
  752. const char *from, uint32 from_length,
  753. CHARSET_INFO *from_cs, uint *errors);
  754. /**
  755. An extended version of my_convert(), to pass non-default mb_wc() and wc_mb().
  756. For example, String::copy_printable() which is used in
  757. Protocol::store_warning() uses this to escape control
  758. and non-convertable characters.
  759. */
  760. uint32 my_convert_using_func(char *to, uint32 to_length, CHARSET_INFO *to_cs,
  761. my_charset_conv_wc_mb mb_wc,
  762. const char *from, uint32 from_length,
  763. CHARSET_INFO *from_cs,
  764. my_charset_conv_mb_wc wc_mb,
  765. uint *errors);
  766. /*
  767. Convert a string between two character sets.
  768. Bad byte sequences as well as characters that cannot be
  769. encoded in the destination character set are replaced to '?'.
  770. Not more than "nchars" characters are copied.
  771. Conversion statistics is returnd in "status" and is set as follows:
  772. - status->m_native_copy_status.m_source_end_pos - to the position
  773. between (src) and (src+src_length), where the function stopped reading
  774. the source string.
  775. - status->m_native_copy_status.m_well_formed_error_pos - to the position
  776. between (src) and (src+src_length), where the first badly formed byte
  777. sequence was found, or to NULL if the string was well formed in the
  778. given range.
  779. - status->m_cannot_convert_error_pos - to the position
  780. between (src) and (src+src_length), where the first character that
  781. cannot be represented in the destination character set was found,
  782. or to NULL if all characters in the given range were successfully
  783. converted.
  784. "src" is allowed to be a NULL pointer. In this case "src_length" must
  785. be equal to 0. All "status" members are initialized to NULL, and 0 is
  786. returned.
  787. */
  788. size_t my_convert_fix(CHARSET_INFO *dstcs, char *dst, size_t dst_length,
  789. CHARSET_INFO *srccs, const char *src, size_t src_length,
  790. size_t nchars, MY_STRCONV_STATUS *status);
  791. #define _MY_U 01 /* Upper case */
  792. #define _MY_L 02 /* Lower case */
  793. #define _MY_NMR 04 /* Numeral (digit) */
  794. #define _MY_SPC 010 /* Spacing character */
  795. #define _MY_PNT 020 /* Punctuation */
  796. #define _MY_CTR 040 /* Control character */
  797. #define _MY_B 0100 /* Blank */
  798. #define _MY_X 0200 /* heXadecimal digit */
  799. #define my_isascii(c) (!((c) & ~0177))
  800. #define my_toascii(c) ((c) & 0177)
  801. #define my_tocntrl(c) ((c) & 31)
  802. #define my_toprint(c) ((c) | 64)
  803. #define my_toupper(s,c) (char) ((s)->to_upper[(uchar) (c)])
  804. #define my_tolower(s,c) (char) ((s)->to_lower[(uchar) (c)])
  805. #define my_isalpha(s, c) (((s)->ctype+1)[(uchar) (c)] & (_MY_U | _MY_L))
  806. #define my_isupper(s, c) (((s)->ctype+1)[(uchar) (c)] & _MY_U)
  807. #define my_islower(s, c) (((s)->ctype+1)[(uchar) (c)] & _MY_L)
  808. #define my_isdigit(s, c) (((s)->ctype+1)[(uchar) (c)] & _MY_NMR)
  809. #define my_isxdigit(s, c) (((s)->ctype+1)[(uchar) (c)] & _MY_X)
  810. #define my_isalnum(s, c) (((s)->ctype+1)[(uchar) (c)] & (_MY_U | _MY_L | _MY_NMR))
  811. #define my_isspace(s, c) (((s)->ctype+1)[(uchar) (c)] & _MY_SPC)
  812. #define my_ispunct(s, c) (((s)->ctype+1)[(uchar) (c)] & _MY_PNT)
  813. #define my_isprint(s, c) (((s)->ctype+1)[(uchar) (c)] & (_MY_PNT | _MY_U | _MY_L | _MY_NMR | _MY_B))
  814. #define my_isgraph(s, c) (((s)->ctype+1)[(uchar) (c)] & (_MY_PNT | _MY_U | _MY_L | _MY_NMR))
  815. #define my_iscntrl(s, c) (((s)->ctype+1)[(uchar) (c)] & _MY_CTR)
  816. /* Some macros that should be cleaned up a little */
  817. #define my_isvar(s,c) (my_isalnum(s,c) || (c) == '_')
  818. #define my_isvar_start(s,c) (my_isalpha(s,c) || (c) == '_')
  819. #define my_binary_compare(s) ((s)->state & MY_CS_BINSORT)
  820. #define use_strnxfrm(s) ((s)->state & MY_CS_STRNXFRM)
  821. #define my_strnxfrm(cs, d, dl, s, sl) \
  822. ((cs)->coll->strnxfrm((cs), (d), (dl), (dl), (s), (sl), MY_STRXFRM_PAD_WITH_SPACE))
  823. #define my_strnncoll(s, a, b, c, d) ((s)->coll->strnncoll((s), (a), (b), (c), (d), 0))
  824. #define my_like_range(s, a, b, c, d, e, f, g, h, i, j) \
  825. ((s)->coll->like_range((s), (a), (b), (c), (d), (e), (f), (g), (h), (i), (j)))
  826. #define my_wildcmp(cs,s,se,w,we,e,o,m) ((cs)->coll->wildcmp((cs),(s),(se),(w),(we),(e),(o),(m)))
  827. #define my_strcasecmp(s, a, b) ((s)->coll->strcasecmp((s), (a), (b)))
  828. #define my_charpos(cs, b, e, num) (cs)->cset->charpos((cs), (const char*) (b), (const char *)(e), (num))
  829. #define use_mb(s) ((s)->cset->ismbchar != NULL)
  830. #define my_ismbchar(s, a, b) ((s)->cset->ismbchar((s), (a), (b)))
  831. #ifdef USE_MB
  832. #define my_mbcharlen(s, a) ((s)->cset->mbcharlen((s),(a)))
  833. #else
  834. #define my_mbcharlen(s, a) 1
  835. #endif
  836. #define my_caseup_str(s, a) ((s)->cset->caseup_str((s), (a)))
  837. #define my_casedn_str(s, a) ((s)->cset->casedn_str((s), (a)))
  838. #define my_strntol(s, a, b, c, d, e) ((s)->cset->strntol((s),(a),(b),(c),(d),(e)))
  839. #define my_strntoul(s, a, b, c, d, e) ((s)->cset->strntoul((s),(a),(b),(c),(d),(e)))
  840. #define my_strntoll(s, a, b, c, d, e) ((s)->cset->strntoll((s),(a),(b),(c),(d),(e)))
  841. #define my_strntoull(s, a, b, c,d, e) ((s)->cset->strntoull((s),(a),(b),(c),(d),(e)))
  842. #define my_strntod(s, a, b, c, d) ((s)->cset->strntod((s),(a),(b),(c),(d)))
  843. /* XXX: still need to take care of this one */
  844. #ifdef MY_CHARSET_TIS620
  845. #error The TIS620 charset is broken at the moment. Tell tim to fix it.
  846. #define USE_TIS620
  847. #include "t_ctype.h"
  848. #endif
  849. #ifdef __cplusplus
  850. }
  851. #endif
  852. #endif /* _m_ctype_h */