~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/charset.h

mergeĀ lp:~linuxjedi/drizzle/trunk-remove-drizzleadmin

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#ifndef DRIZZLED_CHARSET_H
21
 
#define DRIZZLED_CHARSET_H
22
 
 
 
20
/*
 
21
  Header File that defines all the charset declarations being used in Drizzle source code
 
22
*/
 
23
 
 
24
#pragma once
 
25
 
 
26
#include <sys/types.h>
23
27
#include <cstddef>
24
 
#include "drizzled/definitions.h"
25
 
 
26
 
#include "drizzled/visibility.h"
 
28
#include <drizzled/visibility.h>
 
29
#include <drizzled/definitions.h>
27
30
 
28
31
namespace drizzled
29
32
{
30
33
 
31
 
typedef struct charset_info_st CHARSET_INFO;
32
 
 
33
 
extern DRIZZLED_API CHARSET_INFO *all_charsets[256];
34
 
extern CHARSET_INFO compiled_charsets[];
35
 
 
36
 
/* character sets */
37
 
void *cs_alloc(size_t size);
38
 
 
 
34
#define MY_CS_NAME_SIZE                 32
 
35
#define MY_CS_CTYPE_TABLE_SIZE          257
 
36
#define MY_CS_TO_LOWER_TABLE_SIZE       256
 
37
#define MY_CS_TO_UPPER_TABLE_SIZE       256
 
38
#define MY_CS_SORT_ORDER_TABLE_SIZE     256
 
39
#define MY_CS_TO_UNI_TABLE_SIZE         256
 
40
#define CHARSET_DIR     "charsets/"
 
41
#define my_wc_t unsigned long
 
42
/* wm_wc and wc_mb return codes */
 
43
#define MY_CS_ILSEQ     0     /* Wrong by sequence: wb_wc                   */
 
44
#define MY_CS_ILUNI     0     /* Cannot encode Unicode to charset: wc_mb    */
 
45
#define MY_CS_TOOSMALL  -101  /* Need at least one byte:    wc_mb and mb_wc */
 
46
#define MY_CS_TOOSMALL2 -102  /* Need at least two bytes:   wc_mb and mb_wc */
 
47
#define MY_CS_TOOSMALL3 -103  /* Need at least three bytes: wc_mb and mb_wc */
 
48
/* These following three are currently not really used */
 
49
#define MY_CS_TOOSMALL4 -104  /* Need at least 4 bytes: wc_mb and mb_wc */
 
50
#define MY_CS_TOOSMALL5 -105  /* Need at least 5 bytes: wc_mb and mb_wc */
 
51
#define MY_CS_TOOSMALL6 -106  /* Need at least 6 bytes: wc_mb and mb_wc */
 
52
#define MY_SEQ_INTTAIL  1
 
53
#define MY_SEQ_SPACES   2
 
54
#define MY_CS_COMPILED  1      /* compiled-in sets               */
 
55
#define MY_CS_CONFIG    2      /* sets that have a *.conf file   */
 
56
#define MY_CS_INDEX     4      /* sets listed in the Index file  */
 
57
#define MY_CS_LOADED    8      /* sets that are currently loaded */
 
58
#define MY_CS_BINSORT   16     /* if binary sort order           */
 
59
#define MY_CS_PRIMARY   32     /* if primary collation           */
 
60
#define MY_CS_STRNXFRM  64     /* if strnxfrm is used for sort   */
 
61
#define MY_CS_UNICODE   128    /* is a charset is full unicode   */
 
62
#define MY_CS_READY     256    /* if a charset is initialized    */
 
63
#define MY_CS_AVAILABLE 512    /* If either compiled-in or loaded*/
 
64
#define MY_CS_CSSORT    1024   /* if case sensitive sort order   */
 
65
#define MY_CS_HIDDEN    2048   /* don't display in SHOW          */
 
66
#define MY_CS_NONASCII  8192   /* if not ASCII-compatible        */
 
67
#define MY_CHARSET_UNDEFINED 0
 
68
/* Flags for strxfrm */
 
69
#define MY_STRXFRM_LEVEL1          0x00000001 /* for primary weights   */
 
70
#define MY_STRXFRM_LEVEL2          0x00000002 /* for secondary weights */
 
71
#define MY_STRXFRM_LEVEL3          0x00000004 /* for tertiary weights  */
 
72
#define MY_STRXFRM_LEVEL4          0x00000008 /* fourth level weights  */
 
73
#define MY_STRXFRM_LEVEL5          0x00000010 /* fifth level weights   */
 
74
#define MY_STRXFRM_LEVEL6          0x00000020 /* sixth level weights   */
 
75
#define MY_STRXFRM_LEVEL_ALL       0x0000003F /* Bit OR for the above six */
 
76
#define MY_STRXFRM_NLEVELS         6          /* Number of possible levels*/
 
77
#define MY_STRXFRM_PAD_WITH_SPACE  0x00000040 /* if pad result with spaces */
 
78
#define MY_STRXFRM_UNUSED_00000080 0x00000080 /* for future extensions     */
 
79
#define MY_STRXFRM_DESC_LEVEL1     0x00000100 /* if desc order for level1 */
 
80
#define MY_STRXFRM_DESC_LEVEL2     0x00000200 /* if desc order for level2 */
 
81
#define MY_STRXFRM_DESC_LEVEL3     0x00000300 /* if desc order for level3 */
 
82
#define MY_STRXFRM_DESC_LEVEL4     0x00000800 /* if desc order for level4 */
 
83
#define MY_STRXFRM_DESC_LEVEL5     0x00001000 /* if desc order for level5 */
 
84
#define MY_STRXFRM_DESC_LEVEL6     0x00002000 /* if desc order for level6 */
 
85
#define MY_STRXFRM_DESC_SHIFT      8
 
86
#define MY_STRXFRM_UNUSED_00004000 0x00004000 /* for future extensions     */
 
87
#define MY_STRXFRM_UNUSED_00008000 0x00008000 /* for future extensions     */
 
88
#define MY_STRXFRM_REVERSE_LEVEL1  0x00010000 /* if reverse order for level1 */
 
89
#define MY_STRXFRM_REVERSE_LEVEL2  0x00020000 /* if reverse order for level2 */
 
90
#define MY_STRXFRM_REVERSE_LEVEL3  0x00040000 /* if reverse order for level3 */
 
91
#define MY_STRXFRM_REVERSE_LEVEL4  0x00080000 /* if reverse order for level4 */
 
92
#define MY_STRXFRM_REVERSE_LEVEL5  0x00100000 /* if reverse order for level5 */
 
93
#define MY_STRXFRM_REVERSE_LEVEL6  0x00200000 /* if reverse order for level6 */
 
94
#define MY_STRXFRM_REVERSE_SHIFT   16
 
95
#define ILLEGAL_CHARSET_INFO_NUMBER (UINT32_MAX)
 
96
#define MY_UTF8MB4                 "utf8"
 
97
#define my_charset_utf8_general_ci ::drizzled::my_charset_utf8mb4_general_ci
 
98
#define my_charset_utf8_bin        ::drizzled::my_charset_utf8mb4_bin
 
99
#define _MY_U   01      /* Upper case */
 
100
#define _MY_L   02      /* Lower case */
 
101
#define _MY_NMR 04      /* Numeral (digit) */
 
102
#define _MY_SPC 010     /* Spacing character */
 
103
#define _MY_PNT 020     /* Punctuation */
 
104
#define _MY_CTR 040     /* Control character */
 
105
#define _MY_B   0100    /* Blank */
 
106
#define _MY_X   0200    /* heXadecimal digit */
 
107
 
 
108
/* Some typedef to make it easy for C++ to make function pointers */
 
109
typedef int (*my_charset_conv_mb_wc)(const struct charset_info_st * const, my_wc_t *,
 
110
                                     const unsigned char *, const unsigned char *);
 
111
typedef int (*my_charset_conv_wc_mb)(const struct charset_info_st * const, my_wc_t,
 
112
                                     unsigned char *, unsigned char *);
 
113
typedef size_t (*my_charset_conv_case)(const struct charset_info_st * const,
 
114
                                       char *, size_t, char *, size_t);
 
115
struct charset_info_st;
 
116
typedef struct unicase_info_st
 
117
{
 
118
  uint16_t toupper;
 
119
  uint16_t tolower;
 
120
  uint16_t sort;
 
121
} MY_UNICASE_INFO;
 
122
 
 
123
typedef struct uni_ctype_st
 
124
{
 
125
  unsigned char  pctype;
 
126
  unsigned char  *ctype;
 
127
} MY_UNI_CTYPE;
 
128
 
 
129
/* A helper function for "need at least n bytes" */
 
130
inline static int my_cs_toosmalln(int n)
 
131
{
 
132
  return -100-n;
 
133
}
 
134
 
 
135
typedef struct my_uni_idx_st
 
136
{
 
137
  uint16_t from;
 
138
  uint16_t to;
 
139
  unsigned char  *tab;
 
140
} MY_UNI_IDX;
 
141
 
 
142
typedef struct
 
143
{
 
144
  uint32_t beg;
 
145
  uint32_t end;
 
146
  uint32_t mb_len;
 
147
} my_match_t;
 
148
 
 
149
enum my_lex_states
 
150
{
 
151
  MY_LEX_START, MY_LEX_CHAR, MY_LEX_IDENT,
 
152
  MY_LEX_IDENT_SEP, MY_LEX_IDENT_START,
 
153
  MY_LEX_REAL, MY_LEX_HEX_NUMBER, MY_LEX_BIN_NUMBER,
 
154
  MY_LEX_CMP_OP, MY_LEX_LONG_CMP_OP, MY_LEX_STRING, MY_LEX_COMMENT, MY_LEX_END,
 
155
  MY_LEX_OPERATOR_OR_IDENT, MY_LEX_NUMBER_IDENT, MY_LEX_INT_OR_REAL,
 
156
  MY_LEX_REAL_OR_POINT, MY_LEX_BOOL, MY_LEX_EOL, MY_LEX_ESCAPE,
 
157
  MY_LEX_LONG_COMMENT, MY_LEX_END_LONG_COMMENT, MY_LEX_SEMICOLON,
 
158
  MY_LEX_SET_VAR, MY_LEX_USER_END, MY_LEX_HOSTNAME, MY_LEX_SKIP,
 
159
  MY_LEX_USER_VARIABLE_DELIMITER, MY_LEX_SYSTEM_VAR,
 
160
  MY_LEX_IDENT_OR_KEYWORD,
 
161
  MY_LEX_IDENT_OR_HEX, MY_LEX_IDENT_OR_BIN,
 
162
  MY_LEX_STRING_OR_DELIMITER
 
163
};
 
164
 
 
165
struct charset_info_st;
 
166
 
 
167
/* See strings/charset_info_st.txt for information about this structure  */
 
168
typedef struct my_collation_handler_st
 
169
{
 
170
  bool (*init)(struct charset_info_st *, unsigned char *(*alloc)(size_t));
 
171
  /* Collation routines */
 
172
  int     (*strnncoll)(const struct charset_info_st * const,
 
173
                       const unsigned char *, size_t, const unsigned char *, size_t, bool);
 
174
  int     (*strnncollsp)(const struct charset_info_st * const,
 
175
                         const unsigned char *, size_t, const unsigned char *, size_t,
 
176
                         bool diff_if_only_endspace_difference);
 
177
  size_t  (*strnxfrm)(const struct charset_info_st * const,
 
178
                      unsigned char *dst, size_t dstlen, uint32_t nweights,
 
179
                      const unsigned char *src, size_t srclen, uint32_t flags);
 
180
  size_t    (*strnxfrmlen)(const struct charset_info_st * const, size_t);
 
181
  bool (*like_range)(const struct charset_info_st * const,
 
182
                        const char *s, size_t s_length,
 
183
                        char escape, char w_one, char w_many,
 
184
                        size_t res_length,
 
185
                        char *min_str, char *max_str,
 
186
                        size_t *min_len, size_t *max_len);
 
187
  int     (*wildcmp)(const struct charset_info_st * const,
 
188
                     const char *str,const char *str_end,
 
189
                     const char *wildstr,const char *wildend,
 
190
                     int escape,int w_one, int w_many);
 
191
 
 
192
  int  (*strcasecmp)(const struct charset_info_st * const, const char *, const char *);
 
193
 
 
194
  uint32_t (*instr)(const struct charset_info_st * const,
 
195
                const char *b, size_t b_length,
 
196
                const char *s, size_t s_length,
 
197
                my_match_t *match, uint32_t nmatch);
 
198
 
 
199
  /* Hash calculation */
 
200
  void (*hash_sort)(const struct charset_info_st *cs, const unsigned char *key, size_t len,
 
201
                    uint32_t *nr1, uint32_t *nr2);
 
202
  bool (*propagate)(const struct charset_info_st *cs, const unsigned char *str, size_t len);
 
203
} MY_COLLATION_HANDLER;
 
204
 
 
205
/* See strings/charset_info_st.txt about information on this structure  */
 
206
typedef struct my_charset_handler_st
 
207
{
 
208
  bool (*init)(struct charset_info_st *, unsigned char *(*alloc)(size_t));
 
209
  /* Multibyte routines */
 
210
  uint32_t    (*ismbchar)(const struct charset_info_st * const, const char *, const char *);
 
211
  uint32_t    (*mbcharlen)(const struct charset_info_st * const, uint32_t c);
 
212
  size_t  (*numchars)(const struct charset_info_st * const, const char *b, const char *e);
 
213
  size_t  (*charpos)(const struct charset_info_st * const, const char *b, const char *e,
 
214
                     size_t pos);
 
215
  size_t  (*well_formed_len)(const struct charset_info_st * const,
 
216
                             const char *b,const char *e,
 
217
                             size_t nchars, int *error);
 
218
  size_t  (*lengthsp)(const struct charset_info_st * const, const char *ptr, size_t length);
 
219
  size_t  (*numcells)(const struct charset_info_st * const, const char *b, const char *e);
 
220
 
 
221
  /* Unicode conversion */
 
222
  my_charset_conv_mb_wc mb_wc;
 
223
  my_charset_conv_wc_mb wc_mb;
 
224
 
 
225
  /* CTYPE scanner */
 
226
  int (*ctype)(const struct charset_info_st *cs, int *ctype,
 
227
               const unsigned char *s, const unsigned char *e);
 
228
 
 
229
  /* Functions for case and sort conversion */
 
230
  size_t  (*caseup_str)(const struct charset_info_st * const, char *);
 
231
  size_t  (*casedn_str)(const struct charset_info_st * const, char *);
 
232
 
 
233
  my_charset_conv_case caseup;
 
234
  my_charset_conv_case casedn;
 
235
 
 
236
  /* Charset dependant snprintf() */
 
237
  size_t (*snprintf)(const struct charset_info_st * const, char *to, size_t n,
 
238
                     const char *fmt,
 
239
                     ...)
 
240
#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
 
241
                         __attribute__((format(printf, 4, 5)))
 
242
#endif
 
243
                         ;
 
244
  size_t (*long10_to_str)(const struct charset_info_st * const, char *to, size_t n,
 
245
                          int radix, long int val);
 
246
  size_t (*int64_t10_to_str)(const struct charset_info_st * const, char *to, size_t n,
 
247
                              int radix, int64_t val);
 
248
 
 
249
  void (*fill)(const struct charset_info_st * const, char *to, size_t len, int fill);
 
250
 
 
251
  /* String-to-number conversion routines */
 
252
  long        (*strntol)(const struct charset_info_st * const, const char *s, size_t l,
 
253
                         int base, char **e, int *err);
 
254
  unsigned long      (*strntoul)(const struct charset_info_st * const, const char *s, size_t l,
 
255
                         int base, char **e, int *err);
 
256
  int64_t   (*strntoll)(const struct charset_info_st * const, const char *s, size_t l,
 
257
                         int base, char **e, int *err);
 
258
  uint64_t (*strntoull)(const struct charset_info_st * const, const char *s, size_t l,
 
259
                         int base, char **e, int *err);
 
260
  double      (*strntod)(const struct charset_info_st * const, char *s, size_t l, char **e,
 
261
                         int *err);
 
262
  int64_t    (*strtoll10)(const struct charset_info_st *cs,
 
263
                           const char *nptr, char **endptr, int *error);
 
264
  uint64_t   (*strntoull10rnd)(const struct charset_info_st *cs,
 
265
                                const char *str, size_t length,
 
266
                                int unsigned_fl,
 
267
                                char **endptr, int *error);
 
268
  size_t        (*scan)(const struct charset_info_st * const, const char *b, const char *e,
 
269
                        int sq);
 
270
} MY_CHARSET_HANDLER;
 
271
 
 
272
 
 
273
/* See strings/charset_info_st.txt about information on this structure  */
 
274
struct charset_info_st
 
275
{
 
276
  uint32_t      number;
 
277
  uint32_t      primary_number;
 
278
  uint32_t      binary_number;
 
279
  uint32_t      state;
 
280
  const char *csname;
 
281
  const char *name;
 
282
  const char *comment;
 
283
  const char *tailoring;
 
284
  unsigned char    *ctype;
 
285
  unsigned char    *to_lower;
 
286
  unsigned char    *to_upper;
 
287
  unsigned char    *sort_order;
 
288
  uint16_t   *contractions;
 
289
  uint16_t   **sort_order_big;
 
290
  uint16_t      *tab_to_uni;
 
291
  MY_UNI_IDX  *tab_from_uni;
 
292
  MY_UNICASE_INFO **caseinfo;
 
293
  unsigned char     *state_map;
 
294
  unsigned char     *ident_map;
 
295
  uint32_t      strxfrm_multiply;
 
296
  unsigned char     caseup_multiply;
 
297
  unsigned char     casedn_multiply;
 
298
  uint32_t      mbminlen;
 
299
  uint32_t      mbmaxlen;
 
300
  uint16_t    min_sort_char;
 
301
  uint16_t    max_sort_char; /* For LIKE optimization */
 
302
  unsigned char     pad_char;
 
303
  bool   escape_with_backslash_is_dangerous;
 
304
  unsigned char     levels_for_compare;
 
305
  unsigned char     levels_for_order;
 
306
 
 
307
  MY_CHARSET_HANDLER *cset;
 
308
  MY_COLLATION_HANDLER *coll;
 
309
 
 
310
};
 
311
 
 
312
extern DRIZZLED_API charset_info_st *all_charsets[256];
 
313
extern charset_info_st compiled_charsets[];
39
314
extern uint32_t get_charset_number(const char *cs_name, uint32_t cs_flags);
40
315
extern uint32_t get_collation_number(const char *name);
41
316
extern const char *get_charset_name(uint32_t cs_number);
42
 
 
43
 
DRIZZLED_API const CHARSET_INFO *get_charset(uint32_t cs_number);
44
 
DRIZZLED_API const CHARSET_INFO *get_charset_by_name(const char *cs_name);
45
 
DRIZZLED_API const CHARSET_INFO *get_charset_by_csname(const char *cs_name, uint32_t cs_flags);
46
 
 
47
317
extern bool resolve_charset(const char *cs_name,
48
 
                            const CHARSET_INFO *default_cs,
49
 
                            const CHARSET_INFO **cs);
 
318
                            const charset_info_st *default_cs,
 
319
                            const charset_info_st **cs);
50
320
extern bool resolve_collation(const char *cl_name,
51
 
                             const CHARSET_INFO *default_cl,
52
 
                             const CHARSET_INFO **cl);
53
 
 
 
321
                             const charset_info_st *default_cl,
 
322
                             const charset_info_st **cl);
54
323
extern void free_charsets(void);
55
324
extern char *get_charsets_dir(char *buf);
56
 
extern bool my_charset_same(const CHARSET_INFO *cs1, const CHARSET_INFO *cs2);
 
325
extern bool my_charset_same(const charset_info_st *cs1, const charset_info_st *cs2);
57
326
extern bool init_compiled_charsets(myf flags);
58
 
extern void add_compiled_collation(CHARSET_INFO *cs);
59
 
extern size_t escape_string_for_drizzle(const CHARSET_INFO *charset_info,
60
 
                                        char *to, size_t to_length,
61
 
                                        const char *from, size_t length);
62
 
extern size_t escape_quotes_for_drizzle(const CHARSET_INFO *charset_info,
63
 
                                        char *to, size_t to_length,
64
 
                                        const char *from, size_t length);
 
327
extern void add_compiled_collation(charset_info_st *cs);
 
328
extern size_t escape_string_for_drizzle(const charset_info_st *charset_info,
 
329
                                        char *to, size_t to_length,
 
330
                                        const char *from, size_t length);
 
331
extern size_t escape_quotes_for_drizzle(const charset_info_st *charset_info,
 
332
                                        char *to, size_t to_length,
 
333
                                        const char *from, size_t length);
 
334
extern DRIZZLED_API const charset_info_st *default_charset_info;
 
335
extern DRIZZLED_API const charset_info_st *system_charset_info;
 
336
extern const charset_info_st *files_charset_info;
 
337
extern const charset_info_st *table_alias_charset;
 
338
extern MY_UNICASE_INFO *my_unicase_default[256];
 
339
extern MY_UNICASE_INFO *my_unicase_turkish[256];
 
340
extern MY_UNI_CTYPE my_uni_ctype[256];
 
341
extern MY_COLLATION_HANDLER my_collation_mb_bin_handler;
 
342
extern MY_COLLATION_HANDLER my_collation_8bit_simple_ci_handler;
 
343
extern MY_COLLATION_HANDLER my_collation_ucs2_uca_handler;
 
344
extern DRIZZLED_API charset_info_st my_charset_bin;
 
345
extern DRIZZLED_API charset_info_st my_charset_utf8mb4_bin;
 
346
extern DRIZZLED_API charset_info_st my_charset_utf8mb4_general_ci;
 
347
extern DRIZZLED_API charset_info_st my_charset_utf8mb4_unicode_ci;
 
348
size_t my_strnxfrmlen_simple(const charset_info_st * const, size_t);
 
349
extern int  my_strnncollsp_simple(const charset_info_st * const, const unsigned char *, size_t,
 
350
                                  const unsigned char *, size_t,
 
351
                                  bool diff_if_only_endspace_difference);
 
352
extern size_t my_lengthsp_8bit(const charset_info_st * const cs, const char *ptr, size_t length);
 
353
extern uint32_t my_instr_simple(const charset_info_st * const,
 
354
                            const char *b, size_t b_length,
 
355
                            const char *s, size_t s_length,
 
356
                            my_match_t *match, uint32_t nmatch);
 
357
extern MY_CHARSET_HANDLER my_charset_8bit_handler;
 
358
extern MY_CHARSET_HANDLER my_charset_ucs2_handler;
 
359
extern size_t my_caseup_str_mb(const charset_info_st * const, char *);
 
360
extern size_t my_casedn_str_mb(const charset_info_st * const, char *);
 
361
extern size_t my_caseup_mb(const charset_info_st * const, char *src, size_t srclen,
 
362
                                         char *dst, size_t dstlen);
 
363
extern size_t my_casedn_mb(const charset_info_st * const, char *src, size_t srclen,
 
364
                                         char *dst, size_t dstlen);
 
365
extern int my_strcasecmp_mb(const charset_info_st * const  cs, const char *s, const char *t);
 
366
extern bool my_parse_charset_xml(const char *bug, size_t len,
 
367
                                    int (*add)(charset_info_st *cs));
 
368
 
 
369
DRIZZLED_API const charset_info_st *get_charset(uint32_t cs_number);
 
370
DRIZZLED_API const charset_info_st *get_charset_by_name(const char *cs_name);
 
371
DRIZZLED_API const charset_info_st *get_charset_by_csname(const char *cs_name, uint32_t cs_flags);
 
372
 
 
373
/* Functions for 8bit */
 
374
int my_mb_ctype_8bit(const charset_info_st * const,int *, const unsigned char *,const unsigned char *);
 
375
int my_mb_ctype_mb(const charset_info_st * const,int *, const unsigned char *,const unsigned char *);
 
376
 
 
377
size_t my_scan_8bit(const charset_info_st * const cs, const char *b, const char *e, int sq);
 
378
 
 
379
size_t my_snprintf_8bit(const charset_info_st * const, char *to, size_t n,
 
380
                        const char *fmt, ...)
 
381
  __attribute__((format(printf, 4, 5)));
 
382
 
 
383
long       my_strntol_8bit(const charset_info_st * const, const char *s, size_t l, int base,
 
384
                           char **e, int *err);
 
385
unsigned long      my_strntoul_8bit(const charset_info_st * const, const char *s, size_t l, int base,
 
386
                            char **e, int *err);
 
387
int64_t   my_strntoll_8bit(const charset_info_st * const, const char *s, size_t l, int base,
 
388
                            char **e, int *err);
 
389
uint64_t my_strntoull_8bit(const charset_info_st * const, const char *s, size_t l, int base,
 
390
                            char **e, int *err);
 
391
double      my_strntod_8bit(const charset_info_st * const, char *s, size_t l,char **e,
 
392
                            int *err);
 
393
size_t my_long10_to_str_8bit(const charset_info_st * const, char *to, size_t l, int radix,
 
394
                             long int val);
 
395
size_t my_int64_t10_to_str_8bit(const charset_info_st * const, char *to, size_t l, int radix,
 
396
                                 int64_t val);
 
397
int64_t my_strtoll10_8bit(const charset_info_st * const cs,
 
398
                           const char *nptr, char **endptr, int *error);
 
399
int64_t my_strtoll10_ucs2(charset_info_st *cs,
 
400
                           const char *nptr, char **endptr, int *error);
 
401
 
 
402
uint64_t my_strntoull10rnd_8bit(const charset_info_st * const cs,
 
403
                                 const char *str, size_t length, int
 
404
                                 unsigned_fl, char **endptr, int *error);
 
405
uint64_t my_strntoull10rnd_ucs2(charset_info_st *cs,
 
406
                                 const char *str, size_t length,
 
407
                                 int unsigned_fl, char **endptr, int *error);
 
408
 
 
409
void my_fill_8bit(const charset_info_st * const cs, char* to, size_t l, int fill);
 
410
 
 
411
bool  my_like_range_simple(const charset_info_st * const cs,
 
412
                              const char *ptr, size_t ptr_length,
 
413
                              char escape, char w_one, char w_many,
 
414
                              size_t res_length,
 
415
                              char *min_str, char *max_str,
 
416
                              size_t *min_length, size_t *max_length);
 
417
 
 
418
bool  my_like_range_mb(const charset_info_st * const cs,
 
419
                          const char *ptr, size_t ptr_length,
 
420
                          char escape, char w_one, char w_many,
 
421
                          size_t res_length,
 
422
                          char *min_str, char *max_str,
 
423
                          size_t *min_length, size_t *max_length);
 
424
 
 
425
bool  my_like_range_ucs2(const charset_info_st * const cs,
 
426
                            const char *ptr, size_t ptr_length,
 
427
                            char escape, char w_one, char w_many,
 
428
                            size_t res_length,
 
429
                            char *min_str, char *max_str,
 
430
                            size_t *min_length, size_t *max_length);
 
431
 
 
432
bool  my_like_range_utf16(const charset_info_st * const cs,
 
433
                             const char *ptr, size_t ptr_length,
 
434
                             char escape, char w_one, char w_many,
 
435
                             size_t res_length,
 
436
                             char *min_str, char *max_str,
 
437
                             size_t *min_length, size_t *max_length);
 
438
 
 
439
bool  my_like_range_utf32(const charset_info_st * const cs,
 
440
                             const char *ptr, size_t ptr_length,
 
441
                             char escape, char w_one, char w_many,
 
442
                             size_t res_length,
 
443
                             char *min_str, char *max_str,
 
444
                             size_t *min_length, size_t *max_length);
 
445
 
 
446
 
 
447
int my_wildcmp_8bit(const charset_info_st * const,
 
448
                    const char *str,const char *str_end,
 
449
                    const char *wildstr,const char *wildend,
 
450
                    int escape, int w_one, int w_many);
 
451
 
 
452
int my_wildcmp_bin(const charset_info_st * const,
 
453
                   const char *str,const char *str_end,
 
454
                   const char *wildstr,const char *wildend,
 
455
                   int escape, int w_one, int w_many);
 
456
 
 
457
size_t my_numchars_8bit(const charset_info_st * const, const char *b, const char *e);
 
458
size_t my_numcells_8bit(const charset_info_st * const, const char *b, const char *e);
 
459
size_t my_charpos_8bit(const charset_info_st * const, const char *b, const char *e, size_t pos);
 
460
size_t my_well_formed_len_8bit(const charset_info_st * const, const char *b, const char *e,
 
461
                             size_t pos, int *error);
 
462
typedef unsigned char *(*cs_alloc_func)(size_t);
 
463
bool my_coll_init_simple(charset_info_st *cs, cs_alloc_func alloc);
 
464
bool my_cset_init_8bit(charset_info_st *cs, cs_alloc_func alloc);
 
465
uint32_t my_mbcharlen_8bit(const charset_info_st * const, uint32_t c);
 
466
 
 
467
/* Functions for multibyte charsets */
 
468
int my_wildcmp_mb(const charset_info_st * const,
 
469
                  const char *str,const char *str_end,
 
470
                  const char *wildstr,const char *wildend,
 
471
                  int escape, int w_one, int w_many);
 
472
size_t my_numchars_mb(const charset_info_st * const, const char *b, const char *e);
 
473
size_t my_numcells_mb(const charset_info_st * const, const char *b, const char *e);
 
474
size_t my_charpos_mb(const charset_info_st * const, const char *b, const char *e, size_t pos);
 
475
size_t my_well_formed_len_mb(const charset_info_st * const, const char *b, const char *e,
 
476
                             size_t pos, int *error);
 
477
uint32_t my_instr_mb(const charset_info_st * const,
 
478
                 const char *b, size_t b_length,
 
479
                 const char *s, size_t s_length,
 
480
                 my_match_t *match, uint32_t nmatch);
 
481
 
 
482
int my_strnncoll_mb_bin(const charset_info_st * const  cs,
 
483
                        const unsigned char *s, size_t slen,
 
484
                        const unsigned char *t, size_t tlen,
 
485
                        bool t_is_prefix);
 
486
 
 
487
int my_strnncollsp_mb_bin(const charset_info_st * const cs,
 
488
                          const unsigned char *a, size_t a_length,
 
489
                          const unsigned char *b, size_t b_length,
 
490
                          bool diff_if_only_endspace_difference);
 
491
 
 
492
int my_wildcmp_mb_bin(const charset_info_st * const cs,
 
493
                      const char *str,const char *str_end,
 
494
                      const char *wildstr,const char *wildend,
 
495
                      int escape, int w_one, int w_many);
 
496
 
 
497
int my_strcasecmp_mb_bin(const charset_info_st * const, const char *s, const char *t);
 
498
 
 
499
void my_hash_sort_mb_bin(const charset_info_st * const,
 
500
                         const unsigned char *key, size_t len, uint32_t *nr1, uint32_t *nr2);
 
501
 
 
502
size_t my_strnxfrm_mb(const charset_info_st * const,
 
503
                      unsigned char *dst, size_t dstlen, uint32_t nweights,
 
504
                      const unsigned char *src, size_t srclen, uint32_t flags);
 
505
 
 
506
int my_wildcmp_unicode(const charset_info_st * const cs,
 
507
                       const char *str, const char *str_end,
 
508
                       const char *wildstr, const char *wildend,
 
509
                       int escape, int w_one, int w_many,
 
510
                       MY_UNICASE_INFO **weights);
 
511
 
 
512
bool my_propagate_simple(const charset_info_st * const cs, const unsigned char *str, size_t len);
 
513
bool my_propagate_complex(const charset_info_st * const cs, const unsigned char *str, size_t len);
 
514
 
 
515
 
 
516
uint32_t my_strxfrm_flag_normalize(uint32_t flags, uint32_t nlevels);
 
517
void my_strxfrm_desc_and_reverse(unsigned char *str, unsigned char *strend,
 
518
                                 uint32_t flags, uint32_t level);
 
519
size_t my_strxfrm_pad_desc_and_reverse(const charset_info_st * const cs,
 
520
                                       unsigned char *str, unsigned char *frmend, unsigned char *strend,
 
521
                                       uint32_t nweights, uint32_t flags, uint32_t level);
 
522
 
 
523
bool my_charset_is_ascii_compatible(const charset_info_st * const cs);
 
524
 
 
525
/*
 
526
  Compare 0-terminated UTF8 strings.
 
527
 
 
528
  SYNOPSIS
 
529
    my_strcasecmp_utf8mb3()
 
530
    cs                  character set handler
 
531
    s                   First 0-terminated string to compare
 
532
    t                   Second 0-terminated string to compare
 
533
 
 
534
  IMPLEMENTATION
 
535
 
 
536
  RETURN
 
537
    - negative number if s < t
 
538
    - positive number if s > t
 
539
    - 0 is the strings are equal
 
540
*/
 
541
int my_wc_mb_filename(const charset_info_st * const,
 
542
                  my_wc_t wc, unsigned char *s, unsigned char *e);
 
543
 
 
544
int my_mb_wc_filename(const charset_info_st * const,
 
545
                  my_wc_t *pwc, const unsigned char *s, const unsigned char *e);
 
546
 
 
547
 
 
548
unsigned int my_ismbchar_utf8mb4(const charset_info_st * const cs, const char *b, const char *e);
 
549
unsigned int my_mbcharlen_utf8mb4(const charset_info_st * const, uint32_t c);
 
550
 
 
551
size_t my_strnxfrmlen_utf8mb4(const charset_info_st * const, size_t len);
 
552
size_t
 
553
my_strnxfrm_utf8mb4(const charset_info_st * const cs,
 
554
                    unsigned char *dst, size_t dstlen, uint32_t nweights,
 
555
                    const unsigned char *src, size_t srclen, uint32_t flags);
 
556
 
 
557
int my_wildcmp_utf8mb4(const charset_info_st * const cs,
 
558
                   const char *str, const char *strend,
 
559
                   const char *wildstr, const char *wildend,
 
560
                   int escape, int w_one, int w_many);
 
561
int my_strnncollsp_utf8mb4(const charset_info_st * const cs,
 
562
                       const unsigned char *s, size_t slen,
 
563
                       const unsigned char *t, size_t tlen,
 
564
                       bool diff_if_only_endspace_difference);
 
565
int my_strcasecmp_utf8mb4(const charset_info_st * const cs,
 
566
                          const char *s, const char *t);
 
567
 
 
568
int my_strnncoll_utf8mb4(const charset_info_st * const cs,
 
569
                     const unsigned char *s, size_t slen,
 
570
                     const unsigned char *t, size_t tlen,
 
571
                     bool t_is_prefix);
 
572
 
 
573
int my_mb_wc_utf8mb4(const charset_info_st * const cs,
 
574
                 my_wc_t * pwc, const unsigned char *s, const unsigned char *e);
 
575
 
 
576
int my_wc_mb_utf8mb4(const charset_info_st * const cs,
 
577
                 my_wc_t wc, unsigned char *r, unsigned char *e);
 
578
 
 
579
size_t my_caseup_str_utf8mb4(const charset_info_st * const cs, char *src);
 
580
size_t my_casedn_str_utf8mb4(const charset_info_st * const cs, char *src);
 
581
 
 
582
size_t my_caseup_utf8mb4(const charset_info_st * const cs, char *src, size_t srclen,
 
583
                  char *dst, size_t dstlen);
 
584
size_t my_casedn_utf8mb4(const charset_info_st * const cs,
 
585
                  char *src, size_t srclen,
 
586
                  char *dst, size_t dstlen);
 
587
 
 
588
 
 
589
bool my_coll_init_uca(charset_info_st *cs, cs_alloc_func alloc);
 
590
 
 
591
int my_strnncoll_any_uca(const charset_info_st * const cs,
 
592
                         const unsigned char *s, size_t slen,
 
593
                         const unsigned char *t, size_t tlen,
 
594
                         bool t_is_prefix);
 
595
 
 
596
int my_strnncollsp_any_uca(const charset_info_st * const cs,
 
597
                           const unsigned char *s, size_t slen,
 
598
                           const unsigned char *t, size_t tlen,
 
599
                           bool diff_if_only_endspace_difference);
 
600
 
 
601
void my_hash_sort_any_uca(const charset_info_st * const cs,
 
602
                          const unsigned char *s, size_t slen,
 
603
                          uint32_t *n1, uint32_t *n2);
 
604
 
 
605
size_t my_strnxfrm_any_uca(const charset_info_st * const cs,
 
606
                           unsigned char *dst, size_t dstlen, uint32_t nweights,
 
607
                           const unsigned char *src, size_t srclen,
 
608
                           uint32_t flags);
 
609
 
 
610
int my_wildcmp_uca(const charset_info_st * const cs,
 
611
                   const char *str,const char *str_end,
 
612
                   const char *wildstr,const char *wildend,
 
613
                   int escape, int w_one, int w_many);
 
614
 
 
615
int my_strnncoll_8bit_bin(const charset_info_st * const,
 
616
                          const unsigned char *s, size_t slen,
 
617
                          const unsigned char *t, size_t tlen,
 
618
                          bool t_is_prefix);
 
619
int my_strnncollsp_8bit_bin(const charset_info_st * const,
 
620
                            const unsigned char *a, size_t a_length,
 
621
                            const unsigned char *b, size_t b_length,
 
622
                            bool diff_if_only_endspace_difference);
 
623
size_t my_case_str_bin(const charset_info_st * const, char *);
 
624
size_t my_case_bin(const charset_info_st * const, char *,
 
625
                   size_t srclen, char *, size_t);
 
626
int my_strcasecmp_bin(const charset_info_st * const,
 
627
                      const char *s, const char *t);
 
628
size_t my_strnxfrm_8bit_bin(const charset_info_st * const cs,
 
629
                     unsigned char * dst, size_t dstlen, uint32_t nweights,
 
630
                     const unsigned char *src, size_t srclen, uint32_t flags);
 
631
uint32_t my_instr_bin(const charset_info_st * const,
 
632
                      const char *b, size_t b_length,
 
633
                      const char *s, size_t s_length,
 
634
                      my_match_t *match, uint32_t nmatch);
 
635
size_t my_lengthsp_binary(const charset_info_st * const,
 
636
                          const char *, size_t length);
 
637
int my_mb_wc_bin(const charset_info_st * const,
 
638
                 my_wc_t *wc, const unsigned char *str,
 
639
                 const unsigned char *end);
 
640
int my_wc_mb_bin(const charset_info_st * const, my_wc_t wc,
 
641
                 unsigned char *str, unsigned char *end);
 
642
void my_hash_sort_8bit_bin(const charset_info_st * const,
 
643
                           const unsigned char *key, size_t len,
 
644
                           uint32_t *nr1, uint32_t *nr2);
 
645
bool my_coll_init_8bit_bin(charset_info_st *cs,
 
646
                           cs_alloc_func);
 
647
int my_strnncoll_binary(const charset_info_st * const,
 
648
                        const unsigned char *s, size_t slen,
 
649
                        const unsigned char *t, size_t tlen,
 
650
                        bool t_is_prefix);
 
651
int my_strnncollsp_binary(const charset_info_st * const cs,
 
652
                          const unsigned char *s, size_t slen,
 
653
                          const unsigned char *t, size_t tlen,
 
654
                          bool);
 
655
 
 
656
inline static bool my_isascii(char c)      
 
657
{
 
658
  return (!(c & ~0177));
 
659
}
 
660
 
 
661
inline static char my_toascii(char c)
 
662
{
 
663
  return (c & 0177);
 
664
}
 
665
 
 
666
inline static char my_tocntrl(char c) 
 
667
{
 
668
  return (c & 31);
 
669
}
 
670
 
 
671
inline static char my_toprint(char c)
 
672
{
 
673
  return (c | 64);
 
674
}
 
675
 
 
676
inline static char my_toupper(const charset_info_st *s, unsigned char c)
 
677
{
 
678
  return s->to_upper[c];
 
679
}
 
680
 
 
681
inline static char my_tolower(const charset_info_st *s, unsigned char c)
 
682
{
 
683
  return s->to_lower[c];
 
684
}
 
685
 
 
686
inline static bool my_isalpha(const charset_info_st *s, unsigned char c)
 
687
{
 
688
  return (s->ctype+1)[c] & (_MY_U | _MY_L);
 
689
}
 
690
 
 
691
inline static bool my_isupper(const charset_info_st *s, unsigned char c)
 
692
{
 
693
  return (s->ctype+1)[c] & _MY_U;
 
694
}
 
695
 
 
696
inline static bool my_islower(const charset_info_st *s, unsigned char c)
 
697
{
 
698
  return (s->ctype+1)[c] & _MY_L;
 
699
}
 
700
 
 
701
inline static bool my_isdigit(const charset_info_st *s, unsigned char c)
 
702
{
 
703
  return (s->ctype+1)[c] & _MY_NMR;
 
704
}
 
705
 
 
706
inline static bool my_isxdigit(const charset_info_st *s, unsigned char c)
 
707
{
 
708
  return (s->ctype+1)[c] & _MY_X;
 
709
}
 
710
 
 
711
inline static bool my_isalnum(const charset_info_st *s, unsigned char c) 
 
712
{
 
713
  return (s->ctype+1)[c] & (_MY_U | _MY_L | _MY_NMR);
 
714
}
 
715
 
 
716
inline static bool my_isspace(const charset_info_st *s, unsigned char c)
 
717
{
 
718
  return (s->ctype+1)[c] & _MY_SPC;
 
719
}
 
720
 
 
721
inline static bool my_ispunct(const charset_info_st *s, unsigned char c)  
 
722
{
 
723
  return (s->ctype+1)[c] & _MY_PNT;
 
724
}
 
725
 
 
726
inline static bool my_isprint(const charset_info_st *s, unsigned char c)  
 
727
{
 
728
  return (s->ctype+1)[c] & (_MY_PNT | _MY_U | _MY_L | _MY_NMR | _MY_B);
 
729
}
 
730
 
 
731
inline static bool my_isgraph(const charset_info_st *s, unsigned char c)
 
732
{
 
733
  return (s->ctype+1)[c] & (_MY_PNT | _MY_U | _MY_L | _MY_NMR);
 
734
}
 
735
 
 
736
inline static bool my_iscntrl(const charset_info_st *s, unsigned char c)  
 
737
{
 
738
  return (s->ctype+1)[c] & _MY_CTR;
 
739
}
 
740
 
 
741
/* Some macros that should be cleaned up a little */
 
742
inline static bool my_isvar(const charset_info_st *s, char c)
 
743
{
 
744
  return my_isalnum(s,c) || (c) == '_';
 
745
}
 
746
 
 
747
inline static bool my_isvar_start(const charset_info_st *s, char c)
 
748
{
 
749
  return my_isalpha(s,c) || (c) == '_';
 
750
}
 
751
 
 
752
inline static bool my_binary_compare(const charset_info_st *s)
 
753
{
 
754
  return s->state  & MY_CS_BINSORT;
 
755
}
 
756
 
 
757
inline static bool use_strnxfrm(const charset_info_st *s)
 
758
{
 
759
  return s->state & MY_CS_STRNXFRM;
 
760
}
 
761
 
 
762
inline static size_t my_strnxfrm(const charset_info_st *cs, 
 
763
                                 unsigned char *dst, 
 
764
                                 const size_t dstlen, 
 
765
                                 const unsigned char *src, 
 
766
                                 const uint32_t srclen)
 
767
{
 
768
  return (cs->coll->strnxfrm(cs, dst, dstlen, dstlen, src, srclen, MY_STRXFRM_PAD_WITH_SPACE));
 
769
}
 
770
 
 
771
inline static int my_strnncoll(const charset_info_st *cs, 
 
772
                               const unsigned char *s, 
 
773
                               const size_t slen, 
 
774
                               const unsigned char *t,
 
775
                               const size_t tlen) 
 
776
{
 
777
  return (cs->coll->strnncoll(cs, s, slen, t, tlen, 0));
 
778
}
 
779
 
 
780
inline static bool my_like_range(const charset_info_st *cs,
 
781
                                 const char *ptr, const size_t ptrlen,
 
782
                                 const char escape, 
 
783
                                 const char w_one,
 
784
                                 const char w_many, 
 
785
                                 const size_t reslen, 
 
786
                                 char *minstr, char *maxstr, 
 
787
                                 size_t *minlen, size_t *maxlen)
 
788
{
 
789
  return (cs->coll->like_range(cs, ptr, ptrlen, escape, w_one, w_many, reslen, 
 
790
                               minstr, maxstr, minlen, maxlen));
 
791
}
 
792
 
 
793
inline static int my_wildcmp(const charset_info_st *cs,
 
794
                             const char *str, const char *strend,
 
795
                             const char *w_str, const char *w_strend,
 
796
                             const int escape,
 
797
                             const int w_one, const int w_many) 
 
798
{
 
799
  return (cs->coll->wildcmp(cs, str, strend, w_str, w_strend, escape, w_one, w_many));
 
800
}
 
801
 
 
802
inline static int my_strcasecmp(const charset_info_st *cs, const char *s, const char *t)
 
803
{
 
804
  return (cs->coll->strcasecmp(cs, s, t));
 
805
}
 
806
 
 
807
template <typename CHAR_T>
 
808
inline static size_t my_charpos(const charset_info_st *cs, 
 
809
                                const CHAR_T *b, const CHAR_T* e, size_t num)
 
810
{
 
811
  return cs->cset->charpos(cs, reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(e), num);
 
812
}
 
813
 
 
814
inline static bool use_mb(const charset_info_st *cs)
 
815
{
 
816
  return cs->cset->ismbchar != NULL;
 
817
}
 
818
 
 
819
inline static unsigned int  my_ismbchar(const charset_info_st *cs, const char *a, const char *b)
 
820
{
 
821
  return cs->cset->ismbchar(cs, a, b);
 
822
}
 
823
 
 
824
inline static unsigned int my_mbcharlen(const charset_info_st *cs, uint32_t c)
 
825
{
 
826
  return cs->cset->mbcharlen(cs, c);
 
827
}
 
828
 
 
829
 
 
830
inline static size_t my_caseup_str(const charset_info_st *cs, char *src)
 
831
{
 
832
  return cs->cset->caseup_str(cs, src);
 
833
}
 
834
 
 
835
inline static size_t my_casedn_str(const charset_info_st *cs, char *src)
 
836
{
 
837
  return cs->cset->casedn_str(cs, src);
 
838
}
 
839
 
 
840
inline static long my_strntol(const charset_info_st *cs, 
 
841
                              const char* s, const size_t l, const int base, char **e, int *err)
 
842
{
 
843
  return (cs->cset->strntol(cs, s, l, base, e, err));
 
844
}
 
845
 
 
846
inline static unsigned long my_strntoul(const charset_info_st *cs, 
 
847
                                        const char* s, const size_t l, const int base, 
 
848
                                        char **e, int *err)
 
849
{
 
850
  return (cs->cset->strntoul(cs, s, l, base, e, err));
 
851
}
 
852
 
 
853
inline static int64_t my_strntoll(const charset_info_st *cs, 
 
854
                                 const char* s, const size_t l, const int base, char **e, int *err)
 
855
{
 
856
  return (cs->cset->strntoll(cs, s, l, base, e, err));
 
857
}
 
858
 
 
859
inline static int64_t my_strntoull(const charset_info_st *cs, 
 
860
                                   const char* s, const size_t l, const int base, 
 
861
                                   char **e, int *err)
 
862
{
 
863
  return (cs->cset->strntoull(cs, s, l, base, e, err));
 
864
}
 
865
 
 
866
 
 
867
inline static double my_strntod(const charset_info_st *cs, 
 
868
                                char* s, const size_t l, char **e, int *err)
 
869
{
 
870
  return (cs->cset->strntod(cs, s, l, e, err));
 
871
}
 
872
 
 
873
int make_escape_code(const charset_info_st * const cs, const char *escape);
65
874
 
66
875
} /* namespace drizzled */
67
876
 
68
 
#endif /* DRIZZLED_CHARSET_H */