~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/charset.h

  • Committer: Mark Atwood
  • Date: 2011-10-08 04:50:51 UTC
  • mfrom: (2430.1.1 rf)
  • Revision ID: me@mark.atwood.name-20111008045051-6ha1qiy7k2a9c3jv
Tags: 2011.10.27
mergeĀ lp:~olafvdspek/drizzle/refactor2

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
#include <sys/types.h>
27
27
#include <cstddef>
28
 
 
29
28
#include <drizzled/visibility.h>
30
 
#include <drizzled/common_fwd.h>
31
29
#include <drizzled/definitions.h>
32
30
 
33
31
namespace drizzled {
107
105
#define _MY_X   0200    /* heXadecimal digit */
108
106
 
109
107
/* Some typedef to make it easy for C++ to make function pointers */
110
 
typedef int (*my_charset_conv_mb_wc)(const charset_info_st*, my_wc_t *, const unsigned char*, const unsigned char *);
111
 
typedef int (*my_charset_conv_wc_mb)(const charset_info_st*, my_wc_t, unsigned char*, unsigned char *);
112
 
typedef size_t (*my_charset_conv_case)(const charset_info_st*, char*, size_t, char*, size_t);
113
 
 
114
 
struct MY_UNICASE_INFO
 
108
typedef int (*my_charset_conv_mb_wc)(const struct charset_info_st * const, my_wc_t *,
 
109
                                     const unsigned char *, const unsigned char *);
 
110
typedef int (*my_charset_conv_wc_mb)(const struct charset_info_st * const, my_wc_t,
 
111
                                     unsigned char *, unsigned char *);
 
112
typedef size_t (*my_charset_conv_case)(const struct charset_info_st * const,
 
113
                                       char *, size_t, char *, size_t);
 
114
struct charset_info_st;
 
115
typedef struct unicase_info_st
115
116
{
116
117
  uint16_t toupper;
117
118
  uint16_t tolower;
118
119
  uint16_t sort;
119
 
};
120
 
 
121
 
struct MY_UNI_CTYPE
122
 
{
123
 
  unsigned char pctype;
124
 
  unsigned char* ctype;
125
 
};
126
 
 
127
 
struct MY_UNI_IDX
 
120
} MY_UNICASE_INFO;
 
121
 
 
122
typedef struct uni_ctype_st
 
123
{
 
124
  unsigned char  pctype;
 
125
  unsigned char  *ctype;
 
126
} MY_UNI_CTYPE;
 
127
 
 
128
/* A helper function for "need at least n bytes" */
 
129
inline static int my_cs_toosmalln(int n)
 
130
{
 
131
  return -100-n;
 
132
}
 
133
 
 
134
typedef struct my_uni_idx_st
128
135
{
129
136
  uint16_t from;
130
137
  uint16_t to;
131
138
  unsigned char  *tab;
132
 
};
 
139
} MY_UNI_IDX;
133
140
 
134
 
struct my_match_t
 
141
typedef struct
135
142
{
136
143
  uint32_t beg;
137
144
  uint32_t end;
138
145
  uint32_t mb_len;
139
 
};
 
146
} my_match_t;
140
147
 
141
148
enum my_lex_states
142
149
{
154
161
  MY_LEX_STRING_OR_DELIMITER
155
162
};
156
163
 
 
164
struct charset_info_st;
 
165
 
157
166
/* See strings/charset_info_st.txt for information about this structure  */
158
 
struct MY_COLLATION_HANDLER
 
167
typedef struct my_collation_handler_st
159
168
{
160
169
  bool (*init)(charset_info_st&, unsigned char *(*alloc)(size_t));
161
170
  /* Collation routines */
162
 
  int (*strnncoll)(const charset_info_st*, const unsigned char*, size_t, const unsigned char*, size_t, bool);
163
 
  int (*strnncollsp)(const charset_info_st*, const unsigned char*, size_t, const unsigned char*, size_t, bool diff_if_only_endspace_difference);
164
 
  size_t (*strnxfrm)(const charset_info_st*, unsigned char *dst, size_t dstlen, uint32_t nweights, const unsigned char *src, size_t srclen, uint32_t flags);
165
 
  size_t (*strnxfrmlen)(const charset_info_st*, size_t);
166
 
  bool (*like_range)(const charset_info_st*, const char *s, size_t s_length, char escape, char w_one, char w_many, 
167
 
    size_t res_length, char *min_str, char *max_str, size_t *min_len, size_t *max_len);
168
 
  int (*wildcmp)(const charset_info_st*, const char *str,const char *str_end, const char *wildstr, const char *wildend, int escape,int w_one, int w_many);
169
 
 
170
 
  int (*strcasecmp)(const charset_info_st*, const char*, const char *);
171
 
 
172
 
  uint32_t (*instr)(const charset_info_st*, const char *b, size_t b_length, const char *s, size_t s_length, my_match_t *match, uint32_t nmatch);
 
171
  int     (*strnncoll)(const struct charset_info_st * const,
 
172
                       const unsigned char *, size_t, const unsigned char *, size_t, bool);
 
173
  int     (*strnncollsp)(const struct charset_info_st * const,
 
174
                         const unsigned char *, size_t, const unsigned char *, size_t,
 
175
                         bool diff_if_only_endspace_difference);
 
176
  size_t  (*strnxfrm)(const struct charset_info_st * const,
 
177
                      unsigned char *dst, size_t dstlen, uint32_t nweights,
 
178
                      const unsigned char *src, size_t srclen, uint32_t flags);
 
179
  size_t    (*strnxfrmlen)(const struct charset_info_st * const, size_t);
 
180
  bool (*like_range)(const struct charset_info_st * const,
 
181
                        const char *s, size_t s_length,
 
182
                        char escape, char w_one, char w_many,
 
183
                        size_t res_length,
 
184
                        char *min_str, char *max_str,
 
185
                        size_t *min_len, size_t *max_len);
 
186
  int     (*wildcmp)(const struct charset_info_st * const,
 
187
                     const char *str,const char *str_end,
 
188
                     const char *wildstr,const char *wildend,
 
189
                     int escape,int w_one, int w_many);
 
190
 
 
191
  int  (*strcasecmp)(const struct charset_info_st * const, const char *, const char *);
 
192
 
 
193
  uint32_t (*instr)(const struct charset_info_st * const,
 
194
                const char *b, size_t b_length,
 
195
                const char *s, size_t s_length,
 
196
                my_match_t *match, uint32_t nmatch);
173
197
 
174
198
  /* Hash calculation */
175
 
  void (*hash_sort)(const charset_info_st*, const unsigned char *key, size_t len, uint32_t *nr1, uint32_t *nr2);
176
 
  bool (*propagate)();
177
 
};
 
199
  void (*hash_sort)(const struct charset_info_st *cs, const unsigned char *key, size_t len,
 
200
                    uint32_t *nr1, uint32_t *nr2);
 
201
  bool (*propagate)(const struct charset_info_st *cs, const unsigned char *str, size_t len);
 
202
} MY_COLLATION_HANDLER;
178
203
 
179
204
/* See strings/charset_info_st.txt about information on this structure  */
180
 
struct MY_CHARSET_HANDLER
 
205
typedef struct my_charset_handler_st
181
206
{
 
207
  void (*init_unused)();
182
208
  /* Multibyte routines */
183
 
  uint32_t (*ismbchar)(const charset_info_st*, const char*, const char *);
184
 
  uint32_t (*mbcharlen)(const charset_info_st*, uint32_t c);
185
 
  size_t (*numchars)(const charset_info_st*, const char *b, const char *e);
186
 
  size_t (*charpos)(const charset_info_st*, const char *b, const char *e, size_t pos);
187
 
  size_t (*well_formed_len)(const charset_info_st&, str_ref, size_t nchars, int *error);
188
 
  size_t (*lengthsp)(const charset_info_st*, const char *ptr, size_t length);
189
 
  size_t (*numcells)(const charset_info_st*, const char *b, const char *e);
 
209
  uint32_t    (*ismbchar)(const struct charset_info_st * const, const char *, const char *);
 
210
  uint32_t    (*mbcharlen)(const struct charset_info_st * const, uint32_t c);
 
211
  size_t  (*numchars)(const struct charset_info_st * const, const char *b, const char *e);
 
212
  size_t  (*charpos)(const struct charset_info_st * const, const char *b, const char *e,
 
213
                     size_t pos);
 
214
  size_t  (*well_formed_len)(const struct charset_info_st * const,
 
215
                             const char *b,const char *e,
 
216
                             size_t nchars, int *error);
 
217
  size_t  (*lengthsp)(const struct charset_info_st * const, const char *ptr, size_t length);
 
218
  size_t  (*numcells)(const struct charset_info_st * const, const char *b, const char *e);
190
219
 
191
220
  /* Unicode conversion */
192
221
  my_charset_conv_mb_wc mb_wc;
193
222
  my_charset_conv_wc_mb wc_mb;
194
223
 
195
224
  /* CTYPE scanner */
196
 
  int (*ctype)(const charset_info_st *cs, int *ctype, const unsigned char *s, const unsigned char *e);
 
225
  int (*ctype)(const struct charset_info_st *cs, int *ctype,
 
226
               const unsigned char *s, const unsigned char *e);
197
227
 
198
228
  /* Functions for case and sort conversion */
199
 
  size_t (*caseup_str)(const charset_info_st*, char *);
200
 
  size_t (*casedn_str)(const charset_info_st*, char *);
 
229
  size_t  (*caseup_str)(const struct charset_info_st * const, char *);
 
230
  size_t  (*casedn_str)(const struct charset_info_st * const, char *);
201
231
 
202
232
  my_charset_conv_case caseup;
203
233
  my_charset_conv_case casedn;
204
234
 
205
235
  /* Charset dependant snprintf() */
206
 
  size_t (*snprintf)(const charset_info_st*, char *to, size_t n, const char *fmt, ...)
 
236
  size_t (*snprintf)(const struct charset_info_st * const, char *to, size_t n,
 
237
                     const char *fmt,
 
238
                     ...)
207
239
#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
208
240
                         __attribute__((format(printf, 4, 5)))
209
241
#endif
210
242
                         ;
211
 
  size_t (*long10_to_str)(const charset_info_st*, char *to, size_t n, int radix, long int val);
212
 
  size_t (*int64_t10_to_str)(const charset_info_st*, char *to, size_t n, int radix, int64_t val);
 
243
  size_t (*long10_to_str)(const struct charset_info_st * const, char *to, size_t n,
 
244
                          int radix, long int val);
 
245
  size_t (*int64_t10_to_str)(const struct charset_info_st * const, char *to, size_t n,
 
246
                              int radix, int64_t val);
213
247
 
214
 
  void (*fill)(const charset_info_st*, char *to, size_t len, int fill);
 
248
  void (*fill)(const struct charset_info_st * const, char *to, size_t len, int fill);
215
249
 
216
250
  /* String-to-number conversion routines */
217
 
  long (*strntol)(const charset_info_st*, const char *s, size_t l, int base, char **e, int *err);
218
 
  unsigned long (*strntoul)(const charset_info_st*, const char *s, size_t l, int base, char **e, int *err);
219
 
  int64_t (*strntoll)(const charset_info_st*, const char *s, size_t l, int base, char **e, int *err);
220
 
  uint64_t (*strntoull)(const charset_info_st*, const char *s, size_t l, int base, char **e, int *err);
221
 
  double (*strntod)(const charset_info_st*, char *s, size_t l, char **e, int *err);
222
 
  int64_t (*strtoll10)(const charset_info_st*, const char *nptr, char **endptr, int *error);
223
 
  uint64_t (*strntoull10rnd)(const charset_info_st*, const char *str, size_t length, int unsigned_fl, char **endptr, int *error);
224
 
  size_t (*scan)(const charset_info_st*, const char *b, const char *e, int sq);
225
 
};
 
251
  long        (*strntol)(const struct charset_info_st * const, const char *s, size_t l,
 
252
                         int base, char **e, int *err);
 
253
  unsigned long      (*strntoul)(const struct charset_info_st * const, const char *s, size_t l,
 
254
                         int base, char **e, int *err);
 
255
  int64_t   (*strntoll)(const struct charset_info_st * const, const char *s, size_t l,
 
256
                         int base, char **e, int *err);
 
257
  uint64_t (*strntoull)(const struct charset_info_st * const, const char *s, size_t l,
 
258
                         int base, char **e, int *err);
 
259
  double      (*strntod)(const struct charset_info_st * const, char *s, size_t l, char **e,
 
260
                         int *err);
 
261
  int64_t    (*strtoll10)(const struct charset_info_st *cs,
 
262
                           const char *nptr, char **endptr, int *error);
 
263
  uint64_t   (*strntoull10rnd)(const struct charset_info_st *cs,
 
264
                                const char *str, size_t length,
 
265
                                int unsigned_fl,
 
266
                                char **endptr, int *error);
 
267
  size_t        (*scan)(const struct charset_info_st * const, const char *b, const char *e,
 
268
                        int sq);
 
269
} MY_CHARSET_HANDLER;
 
270
 
226
271
 
227
272
/* See strings/charset_info_st.txt about information on this structure  */
228
273
struct charset_info_st
254
299
  uint16_t    min_sort_char;
255
300
  uint16_t    max_sort_char; /* For LIKE optimization */
256
301
  unsigned char     pad_char;
 
302
  bool   escape_with_backslash_is_dangerous;
257
303
  unsigned char     levels_for_compare;
258
304
  unsigned char     levels_for_order;
259
305
 
260
306
  MY_CHARSET_HANDLER *cset;
261
307
  MY_COLLATION_HANDLER *coll;
262
308
 
263
 
  bool isalpha(unsigned char c) const
264
 
  {
265
 
    return ctype[c + 1] & (_MY_U | _MY_L);
266
 
  }
267
 
 
268
 
  bool isupper(unsigned char c) const
269
 
  {
270
 
    return ctype[c + 1] & _MY_U;
271
 
  }
272
 
 
273
 
  bool islower(unsigned char c) const
274
 
  {
275
 
    return ctype[c + 1] & _MY_L;
276
 
  }
277
 
 
278
 
  bool isdigit(unsigned char c) const
279
 
  {
280
 
    return ctype[c + 1] & _MY_NMR;
281
 
  }
282
 
 
283
 
  bool isxdigit(unsigned char c) const
284
 
  {
285
 
    return ctype[c + 1] & _MY_X;
286
 
  }
287
 
 
288
 
  bool isalnum(unsigned char c) const
289
 
  {
290
 
    return ctype[c + 1] & (_MY_U | _MY_L | _MY_NMR);
291
 
  }
292
 
 
293
 
  bool isspace(unsigned char c) const
294
 
  {
295
 
    return ctype[c + 1] & _MY_SPC;
296
 
  }
297
 
 
298
 
  bool ispunct(unsigned char c) const  
299
 
  {
300
 
    return ctype[c + 1] & _MY_PNT;
301
 
  }
302
 
 
303
 
  bool isprint(unsigned char c) const
304
 
  {
305
 
    return ctype[c + 1] & (_MY_PNT | _MY_U | _MY_L | _MY_NMR | _MY_B);
306
 
  }
307
 
 
308
 
  bool isgraph(unsigned char c) const
309
 
  {
310
 
    return ctype[c + 1] & (_MY_PNT | _MY_U | _MY_L | _MY_NMR);
311
 
  }
312
 
 
313
 
  bool iscntrl(unsigned char c) const
314
 
  {
315
 
    return ctype[c + 1] & _MY_CTR;
316
 
  }
317
 
 
318
 
  bool isvar(char c) const
319
 
  {
320
 
    return isalnum(c) || (c) == '_';
321
 
  }
322
 
 
323
 
  char toupper(unsigned char c) const
324
 
  {
325
 
    return to_upper[c];
326
 
  }
327
 
 
328
 
  char tolower(unsigned char c) const
329
 
  {
330
 
    return to_lower[c];
331
 
  }
332
 
 
333
 
  bool binary_compare() const
334
 
  {
335
 
    return state  & MY_CS_BINSORT;
336
 
  }
337
 
 
338
 
  bool use_strnxfrm() const
339
 
  {
340
 
    return state & MY_CS_STRNXFRM;
341
 
  }
342
 
 
343
 
  size_t strnxfrm(unsigned char *dst, const size_t dstlen, const unsigned char *src, const uint32_t srclen) const
344
 
  {
345
 
    return coll->strnxfrm(this, dst, dstlen, dstlen, src, srclen, MY_STRXFRM_PAD_WITH_SPACE);
346
 
  }
347
 
 
348
 
  int strcasecmp(const char *s, const char *t) const
349
 
  {
350
 
    return coll->strcasecmp(this, s, t);
351
 
  }
352
 
 
353
 
  size_t caseup_str(char* src) const
354
 
  {
355
 
    return cset->caseup_str(this, src);
356
 
  }
357
 
 
358
 
  size_t casedn_str(char* src) const
359
 
  {
360
 
    return cset->casedn_str(this, src);
361
 
  }
362
309
};
363
310
 
364
311
extern DRIZZLED_API charset_info_st *all_charsets[256];
365
 
uint32_t get_charset_number(const char *cs_name, uint32_t cs_flags);
366
 
uint32_t get_collation_number(const char *name);
367
 
const char *get_charset_name(uint32_t cs_number);
368
 
void free_charsets();
369
 
bool my_charset_same(const charset_info_st*, const charset_info_st*);
370
 
size_t escape_string_for_drizzle(const charset_info_st *charset_info, char *to, size_t to_length, const char *from, size_t length);
371
 
size_t escape_quotes_for_drizzle(const charset_info_st *charset_info, char *to, size_t to_length, const char *from, size_t length);
 
312
extern charset_info_st compiled_charsets[];
 
313
extern uint32_t get_charset_number(const char *cs_name, uint32_t cs_flags);
 
314
extern uint32_t get_collation_number(const char *name);
 
315
extern const char *get_charset_name(uint32_t cs_number);
 
316
extern bool resolve_charset(const char *cs_name,
 
317
                            const charset_info_st *default_cs,
 
318
                            const charset_info_st **cs);
 
319
extern bool resolve_collation(const char *cl_name,
 
320
                             const charset_info_st *default_cl,
 
321
                             const charset_info_st **cl);
 
322
extern void free_charsets();
 
323
extern char *get_charsets_dir(char *buf);
 
324
extern bool my_charset_same(const charset_info_st *cs1, const charset_info_st *cs2);
 
325
extern size_t escape_string_for_drizzle(const charset_info_st *charset_info,
 
326
                                        char *to, size_t to_length,
 
327
                                        const char *from, size_t length);
 
328
extern size_t escape_quotes_for_drizzle(const charset_info_st *charset_info,
 
329
                                        char *to, size_t to_length,
 
330
                                        const char *from, size_t length);
372
331
extern DRIZZLED_API const charset_info_st *default_charset_info;
373
332
extern DRIZZLED_API const charset_info_st *system_charset_info;
374
333
extern const charset_info_st *files_charset_info;
380
339
extern DRIZZLED_API charset_info_st my_charset_utf8mb4_bin;
381
340
extern DRIZZLED_API charset_info_st my_charset_utf8mb4_general_ci;
382
341
extern DRIZZLED_API charset_info_st my_charset_utf8mb4_unicode_ci;
383
 
size_t my_strnxfrmlen_simple(const charset_info_st*, size_t);
384
 
int my_strnncollsp_simple(const charset_info_st*, const unsigned char*, size_t, const unsigned char*, size_t, bool diff_if_only_endspace_difference);
385
 
size_t my_lengthsp_8bit(const charset_info_st*, const char *ptr, size_t length);
386
 
uint32_t my_instr_simple(const charset_info_st*, const char *b, size_t b_length, const char *s, size_t s_length, my_match_t *match, uint32_t nmatch);
387
 
int my_strcasecmp_mb(const charset_info_st*, const char *s, const char *t);
 
342
size_t my_strnxfrmlen_simple(const charset_info_st * const, size_t);
 
343
extern int  my_strnncollsp_simple(const charset_info_st * const, const unsigned char *, size_t,
 
344
                                  const unsigned char *, size_t,
 
345
                                  bool diff_if_only_endspace_difference);
 
346
extern size_t my_lengthsp_8bit(const charset_info_st * const cs, const char *ptr, size_t length);
 
347
extern uint32_t my_instr_simple(const charset_info_st * const,
 
348
                            const char *b, size_t b_length,
 
349
                            const char *s, size_t s_length,
 
350
                            my_match_t *match, uint32_t nmatch);
 
351
extern MY_CHARSET_HANDLER my_charset_8bit_handler;
 
352
extern MY_CHARSET_HANDLER my_charset_ucs2_handler;
 
353
extern int my_strcasecmp_mb(const charset_info_st * const  cs, const char *s, const char *t);
 
354
extern bool my_parse_charset_xml(const char *bug, size_t len,
 
355
                                    int (*add)(charset_info_st *cs));
388
356
 
389
357
DRIZZLED_API const charset_info_st *get_charset(uint32_t cs_number);
390
358
DRIZZLED_API const charset_info_st *get_charset_by_name(const char *cs_name);
391
359
DRIZZLED_API const charset_info_st *get_charset_by_csname(const char *cs_name, uint32_t cs_flags);
392
360
 
393
361
/* Functions for 8bit */
394
 
int my_mb_ctype_8bit(const charset_info_st*, int*, const unsigned char*, const unsigned char *);
395
 
int my_mb_ctype_mb(const charset_info_st*, int*, const unsigned char*, const unsigned char *);
396
 
 
397
 
size_t my_scan_8bit(const charset_info_st*, const char *b, const char *e, int sq);
398
 
size_t my_snprintf_8bit(const charset_info_st*, char *to, size_t n, const char *fmt, ...) __attribute__((format(printf, 4, 5)));
399
 
 
400
 
long my_strntol_8bit(const charset_info_st*, const char *s, size_t l, int base, char **e, int *err);
401
 
unsigned long my_strntoul_8bit(const charset_info_st*, const char *s, size_t l, int base, char **e, int *err);
402
 
int64_t my_strntoll_8bit(const charset_info_st*, const char *s, size_t l, int base, char **e, int *err);
403
 
uint64_t my_strntoull_8bit(const charset_info_st*, const char *s, size_t l, int base, char **e, int *err);
404
 
double my_strntod_8bit(const charset_info_st*, char *s, size_t l,char **e, int *err);
405
 
size_t my_long10_to_str_8bit(const charset_info_st*, char *to, size_t l, int radix, long int val);
406
 
size_t my_int64_t10_to_str_8bit(const charset_info_st*, char *to, size_t l, int radix, int64_t val);
407
 
int64_t my_strtoll10_8bit(const charset_info_st*, const char *nptr, char **endptr, int *error);
408
 
 
409
 
uint64_t my_strntoull10rnd_8bit(const charset_info_st*, const char *str, size_t length, int unsigned_fl, char **endptr, int *error);
410
 
 
411
 
void my_fill_8bit(const charset_info_st*, char* to, size_t l, int fill);
412
 
 
413
 
bool  my_like_range_simple(const charset_info_st*,
 
362
int my_mb_ctype_8bit(const charset_info_st * const,int *, const unsigned char *,const unsigned char *);
 
363
int my_mb_ctype_mb(const charset_info_st * const,int *, const unsigned char *,const unsigned char *);
 
364
 
 
365
size_t my_scan_8bit(const charset_info_st * const cs, const char *b, const char *e, int sq);
 
366
 
 
367
size_t my_snprintf_8bit(const charset_info_st * const, char *to, size_t n,
 
368
                        const char *fmt, ...)
 
369
  __attribute__((format(printf, 4, 5)));
 
370
 
 
371
long       my_strntol_8bit(const charset_info_st * const, const char *s, size_t l, int base,
 
372
                           char **e, int *err);
 
373
unsigned long      my_strntoul_8bit(const charset_info_st * const, const char *s, size_t l, int base,
 
374
                            char **e, int *err);
 
375
int64_t   my_strntoll_8bit(const charset_info_st * const, const char *s, size_t l, int base,
 
376
                            char **e, int *err);
 
377
uint64_t my_strntoull_8bit(const charset_info_st * const, const char *s, size_t l, int base,
 
378
                            char **e, int *err);
 
379
double      my_strntod_8bit(const charset_info_st * const, char *s, size_t l,char **e,
 
380
                            int *err);
 
381
size_t my_long10_to_str_8bit(const charset_info_st * const, char *to, size_t l, int radix,
 
382
                             long int val);
 
383
size_t my_int64_t10_to_str_8bit(const charset_info_st * const, char *to, size_t l, int radix,
 
384
                                 int64_t val);
 
385
int64_t my_strtoll10_8bit(const charset_info_st * const cs,
 
386
                           const char *nptr, char **endptr, int *error);
 
387
int64_t my_strtoll10_ucs2(charset_info_st *cs,
 
388
                           const char *nptr, char **endptr, int *error);
 
389
 
 
390
uint64_t my_strntoull10rnd_8bit(const charset_info_st * const cs,
 
391
                                 const char *str, size_t length, int
 
392
                                 unsigned_fl, char **endptr, int *error);
 
393
uint64_t my_strntoull10rnd_ucs2(charset_info_st *cs,
 
394
                                 const char *str, size_t length,
 
395
                                 int unsigned_fl, char **endptr, int *error);
 
396
 
 
397
void my_fill_8bit(const charset_info_st * const cs, char* to, size_t l, int fill);
 
398
 
 
399
bool  my_like_range_simple(const charset_info_st * const cs,
414
400
                              const char *ptr, size_t ptr_length,
415
401
                              char escape, char w_one, char w_many,
416
402
                              size_t res_length,
417
403
                              char *min_str, char *max_str,
418
404
                              size_t *min_length, size_t *max_length);
419
405
 
420
 
bool  my_like_range_mb(const charset_info_st*,
 
406
bool  my_like_range_mb(const charset_info_st * const cs,
421
407
                          const char *ptr, size_t ptr_length,
422
408
                          char escape, char w_one, char w_many,
423
409
                          size_t res_length,
424
410
                          char *min_str, char *max_str,
425
411
                          size_t *min_length, size_t *max_length);
426
412
 
427
 
int my_wildcmp_8bit(const charset_info_st*,
 
413
bool  my_like_range_ucs2(const charset_info_st * const cs,
 
414
                            const char *ptr, size_t ptr_length,
 
415
                            char escape, char w_one, char w_many,
 
416
                            size_t res_length,
 
417
                            char *min_str, char *max_str,
 
418
                            size_t *min_length, size_t *max_length);
 
419
 
 
420
bool  my_like_range_utf16(const charset_info_st * const cs,
 
421
                             const char *ptr, size_t ptr_length,
 
422
                             char escape, char w_one, char w_many,
 
423
                             size_t res_length,
 
424
                             char *min_str, char *max_str,
 
425
                             size_t *min_length, size_t *max_length);
 
426
 
 
427
bool  my_like_range_utf32(const charset_info_st * const cs,
 
428
                             const char *ptr, size_t ptr_length,
 
429
                             char escape, char w_one, char w_many,
 
430
                             size_t res_length,
 
431
                             char *min_str, char *max_str,
 
432
                             size_t *min_length, size_t *max_length);
 
433
 
 
434
 
 
435
int my_wildcmp_8bit(const charset_info_st * const,
428
436
                    const char *str,const char *str_end,
429
437
                    const char *wildstr,const char *wildend,
430
438
                    int escape, int w_one, int w_many);
431
439
 
432
 
int my_wildcmp_bin(const charset_info_st*,
 
440
int my_wildcmp_bin(const charset_info_st * const,
433
441
                   const char *str,const char *str_end,
434
442
                   const char *wildstr,const char *wildend,
435
443
                   int escape, int w_one, int w_many);
436
444
 
437
 
size_t my_numchars_8bit(const charset_info_st*, const char *b, const char *e);
438
 
size_t my_numcells_8bit(const charset_info_st*, const char *b, const char *e);
439
 
size_t my_charpos_8bit(const charset_info_st*, const char *b, const char *e, size_t pos);
440
 
size_t my_well_formed_len_8bit(const charset_info_st&, str_ref, size_t pos, int *error);
 
445
size_t my_numchars_8bit(const charset_info_st * const, const char *b, const char *e);
 
446
size_t my_numcells_8bit(const charset_info_st * const, const char *b, const char *e);
 
447
size_t my_charpos_8bit(const charset_info_st * const, const char *b, const char *e, size_t pos);
 
448
size_t my_well_formed_len_8bit(const charset_info_st * const, const char *b, const char *e,
 
449
                             size_t pos, int *error);
441
450
typedef unsigned char *(*cs_alloc_func)(size_t);
442
451
bool my_coll_init_simple(charset_info_st *cs, cs_alloc_func alloc);
443
452
bool my_cset_init_8bit(charset_info_st *cs, cs_alloc_func alloc);
444
 
uint32_t my_mbcharlen_8bit(const charset_info_st*, uint32_t c);
 
453
uint32_t my_mbcharlen_8bit(const charset_info_st * const, uint32_t c);
445
454
 
446
455
/* Functions for multibyte charsets */
447
 
int my_wildcmp_mb(const charset_info_st*,
 
456
int my_wildcmp_mb(const charset_info_st * const,
448
457
                  const char *str,const char *str_end,
449
458
                  const char *wildstr,const char *wildend,
450
459
                  int escape, int w_one, int w_many);
451
 
size_t my_numchars_mb(const charset_info_st*, const char *b, const char *e);
452
 
size_t my_numcells_mb(const charset_info_st*, const char *b, const char *e);
453
 
size_t my_charpos_mb(const charset_info_st*, const char *b, const char *e, size_t pos);
454
 
size_t my_well_formed_len_mb(const charset_info_st&, str_ref, size_t pos, int *error);
455
 
uint32_t my_instr_mb(const charset_info_st*,
 
460
size_t my_numchars_mb(const charset_info_st * const, const char *b, const char *e);
 
461
size_t my_numcells_mb(const charset_info_st * const, const char *b, const char *e);
 
462
size_t my_charpos_mb(const charset_info_st * const, const char *b, const char *e, size_t pos);
 
463
size_t my_well_formed_len_mb(const charset_info_st * const, const char *b, const char *e,
 
464
                             size_t pos, int *error);
 
465
uint32_t my_instr_mb(const charset_info_st * const,
456
466
                 const char *b, size_t b_length,
457
467
                 const char *s, size_t s_length,
458
468
                 my_match_t *match, uint32_t nmatch);
459
469
 
460
 
int my_strnncoll_mb_bin(const charset_info_st*  cs,
 
470
int my_strnncoll_mb_bin(const charset_info_st * const  cs,
461
471
                        const unsigned char *s, size_t slen,
462
472
                        const unsigned char *t, size_t tlen,
463
473
                        bool t_is_prefix);
464
474
 
465
 
int my_strnncollsp_mb_bin(const charset_info_st*,
 
475
int my_strnncollsp_mb_bin(const charset_info_st * const cs,
466
476
                          const unsigned char *a, size_t a_length,
467
477
                          const unsigned char *b, size_t b_length,
468
478
                          bool diff_if_only_endspace_difference);
469
479
 
470
 
int my_wildcmp_mb_bin(const charset_info_st*,
 
480
int my_wildcmp_mb_bin(const charset_info_st * const cs,
471
481
                      const char *str,const char *str_end,
472
482
                      const char *wildstr,const char *wildend,
473
483
                      int escape, int w_one, int w_many);
474
484
 
475
 
int my_strcasecmp_mb_bin(const charset_info_st*, const char *s, const char *t);
 
485
int my_strcasecmp_mb_bin(const charset_info_st * const, const char *s, const char *t);
476
486
 
477
 
void my_hash_sort_mb_bin(const charset_info_st*,
 
487
void my_hash_sort_mb_bin(const charset_info_st * const,
478
488
                         const unsigned char *key, size_t len, uint32_t *nr1, uint32_t *nr2);
479
489
 
480
 
size_t my_strnxfrm_mb(const charset_info_st*,
 
490
size_t my_strnxfrm_mb(const charset_info_st * const,
481
491
                      unsigned char *dst, size_t dstlen, uint32_t nweights,
482
492
                      const unsigned char *src, size_t srclen, uint32_t flags);
483
493
 
484
 
int my_wildcmp_unicode(const charset_info_st*,
 
494
int my_wildcmp_unicode(const charset_info_st * const cs,
485
495
                       const char *str, const char *str_end,
486
496
                       const char *wildstr, const char *wildend,
487
497
                       int escape, int w_one, int w_many,
488
498
                       MY_UNICASE_INFO **weights);
489
499
 
490
 
bool my_propagate_simple();
491
 
bool my_propagate_complex();
 
500
bool my_propagate_simple(const charset_info_st * const cs, const unsigned char *str, size_t len);
 
501
bool my_propagate_complex(const charset_info_st * const cs, const unsigned char *str, size_t len);
492
502
 
493
503
 
494
504
uint32_t my_strxfrm_flag_normalize(uint32_t flags, uint32_t nlevels);
495
505
void my_strxfrm_desc_and_reverse(unsigned char *str, unsigned char *strend,
496
506
                                 uint32_t flags, uint32_t level);
497
 
size_t my_strxfrm_pad_desc_and_reverse(const charset_info_st*,
 
507
size_t my_strxfrm_pad_desc_and_reverse(const charset_info_st * const cs,
498
508
                                       unsigned char *str, unsigned char *frmend, unsigned char *strend,
499
509
                                       uint32_t nweights, uint32_t flags, uint32_t level);
500
510
 
501
 
bool my_charset_is_ascii_compatible(const charset_info_st*);
 
511
bool my_charset_is_ascii_compatible(const charset_info_st * const cs);
502
512
 
503
513
/*
504
514
  Compare 0-terminated UTF8 strings.
516
526
    - positive number if s > t
517
527
    - 0 is the strings are equal
518
528
*/
519
 
int my_wc_mb_filename(const charset_info_st*, my_wc_t wc, unsigned char *s, unsigned char *e);
520
 
int my_mb_wc_filename(const charset_info_st*, my_wc_t *pwc, const unsigned char *s, const unsigned char *e);
521
 
 
522
 
int my_strnncoll_8bit_bin(const charset_info_st*,
 
529
int my_wc_mb_filename(const charset_info_st * const,
 
530
                  my_wc_t wc, unsigned char *s, unsigned char *e);
 
531
 
 
532
int my_mb_wc_filename(const charset_info_st * const,
 
533
                  my_wc_t *pwc, const unsigned char *s, const unsigned char *e);
 
534
 
 
535
 
 
536
unsigned int my_ismbchar_utf8mb4(const charset_info_st * const cs, const char *b, const char *e);
 
537
unsigned int my_mbcharlen_utf8mb4(const charset_info_st * const, uint32_t c);
 
538
 
 
539
size_t my_strnxfrmlen_utf8mb4(const charset_info_st * const, size_t len);
 
540
size_t
 
541
my_strnxfrm_utf8mb4(const charset_info_st * const cs,
 
542
                    unsigned char *dst, size_t dstlen, uint32_t nweights,
 
543
                    const unsigned char *src, size_t srclen, uint32_t flags);
 
544
 
 
545
int my_wildcmp_utf8mb4(const charset_info_st * const cs,
 
546
                   const char *str, const char *strend,
 
547
                   const char *wildstr, const char *wildend,
 
548
                   int escape, int w_one, int w_many);
 
549
int my_strnncollsp_utf8mb4(const charset_info_st * const cs,
 
550
                       const unsigned char *s, size_t slen,
 
551
                       const unsigned char *t, size_t tlen,
 
552
                       bool diff_if_only_endspace_difference);
 
553
int my_strcasecmp_utf8mb4(const charset_info_st * const cs,
 
554
                          const char *s, const char *t);
 
555
 
 
556
int my_strnncoll_utf8mb4(const charset_info_st * const cs,
 
557
                     const unsigned char *s, size_t slen,
 
558
                     const unsigned char *t, size_t tlen,
 
559
                     bool t_is_prefix);
 
560
 
 
561
int my_mb_wc_utf8mb4(const charset_info_st * const cs,
 
562
                 my_wc_t * pwc, const unsigned char *s, const unsigned char *e);
 
563
 
 
564
int my_wc_mb_utf8mb4(const charset_info_st * const cs,
 
565
                 my_wc_t wc, unsigned char *r, unsigned char *e);
 
566
 
 
567
size_t my_caseup_str_utf8mb4(const charset_info_st * const cs, char *src);
 
568
size_t my_casedn_str_utf8mb4(const charset_info_st * const cs, char *src);
 
569
 
 
570
size_t my_caseup_utf8mb4(const charset_info_st * const cs, char *src, size_t srclen,
 
571
                  char *dst, size_t dstlen);
 
572
size_t my_casedn_utf8mb4(const charset_info_st * const cs,
 
573
                  char *src, size_t srclen,
 
574
                  char *dst, size_t dstlen);
 
575
 
 
576
 
 
577
int my_strnncoll_any_uca(const charset_info_st * const cs,
 
578
                         const unsigned char *s, size_t slen,
 
579
                         const unsigned char *t, size_t tlen,
 
580
                         bool t_is_prefix);
 
581
 
 
582
int my_strnncollsp_any_uca(const charset_info_st * const cs,
 
583
                           const unsigned char *s, size_t slen,
 
584
                           const unsigned char *t, size_t tlen,
 
585
                           bool diff_if_only_endspace_difference);
 
586
 
 
587
void my_hash_sort_any_uca(const charset_info_st * const cs,
 
588
                          const unsigned char *s, size_t slen,
 
589
                          uint32_t *n1, uint32_t *n2);
 
590
 
 
591
size_t my_strnxfrm_any_uca(const charset_info_st * const cs,
 
592
                           unsigned char *dst, size_t dstlen, uint32_t nweights,
 
593
                           const unsigned char *src, size_t srclen,
 
594
                           uint32_t flags);
 
595
 
 
596
int my_wildcmp_uca(const charset_info_st * const cs,
 
597
                   const char *str,const char *str_end,
 
598
                   const char *wildstr,const char *wildend,
 
599
                   int escape, int w_one, int w_many);
 
600
 
 
601
int my_strnncoll_8bit_bin(const charset_info_st * const,
523
602
                          const unsigned char *s, size_t slen,
524
603
                          const unsigned char *t, size_t tlen,
525
604
                          bool t_is_prefix);
526
 
int my_strnncollsp_8bit_bin(const charset_info_st*,
 
605
int my_strnncollsp_8bit_bin(const charset_info_st * const,
527
606
                            const unsigned char *a, size_t a_length,
528
607
                            const unsigned char *b, size_t b_length,
529
608
                            bool diff_if_only_endspace_difference);
530
 
size_t my_case_str_bin(const charset_info_st*, char *);
531
 
size_t my_case_bin(const charset_info_st*, char*,
532
 
                   size_t srclen, char*, size_t);
533
 
int my_strcasecmp_bin(const charset_info_st*,
 
609
size_t my_case_str_bin(const charset_info_st * const, char *);
 
610
size_t my_case_bin(const charset_info_st * const, char *,
 
611
                   size_t srclen, char *, size_t);
 
612
int my_strcasecmp_bin(const charset_info_st * const,
534
613
                      const char *s, const char *t);
535
 
size_t my_strnxfrm_8bit_bin(const charset_info_st*,
 
614
size_t my_strnxfrm_8bit_bin(const charset_info_st * const cs,
536
615
                     unsigned char * dst, size_t dstlen, uint32_t nweights,
537
616
                     const unsigned char *src, size_t srclen, uint32_t flags);
538
 
uint32_t my_instr_bin(const charset_info_st*,
 
617
uint32_t my_instr_bin(const charset_info_st * const,
539
618
                      const char *b, size_t b_length,
540
619
                      const char *s, size_t s_length,
541
620
                      my_match_t *match, uint32_t nmatch);
542
 
size_t my_lengthsp_binary(const charset_info_st*,
543
 
                          const char*, size_t length);
544
 
int my_mb_wc_bin(const charset_info_st*,
 
621
size_t my_lengthsp_binary(const charset_info_st * const,
 
622
                          const char *, size_t length);
 
623
int my_mb_wc_bin(const charset_info_st * const,
545
624
                 my_wc_t *wc, const unsigned char *str,
546
625
                 const unsigned char *end);
547
 
int my_wc_mb_bin(const charset_info_st*, my_wc_t wc,
 
626
int my_wc_mb_bin(const charset_info_st * const, my_wc_t wc,
548
627
                 unsigned char *str, unsigned char *end);
549
 
void my_hash_sort_8bit_bin(const charset_info_st*,
 
628
void my_hash_sort_8bit_bin(const charset_info_st * const,
550
629
                           const unsigned char *key, size_t len,
551
630
                           uint32_t *nr1, uint32_t *nr2);
552
631
bool my_coll_init_8bit_bin(charset_info_st *cs,
553
632
                           cs_alloc_func);
554
 
int my_strnncoll_binary(const charset_info_st*,
 
633
int my_strnncoll_binary(const charset_info_st * const,
555
634
                        const unsigned char *s, size_t slen,
556
635
                        const unsigned char *t, size_t tlen,
557
636
                        bool t_is_prefix);
558
 
int my_strnncollsp_binary(const charset_info_st*,
 
637
int my_strnncollsp_binary(const charset_info_st * const cs,
559
638
                          const unsigned char *s, size_t slen,
560
639
                          const unsigned char *t, size_t tlen,
561
640
                          bool);
562
641
 
 
642
inline static bool my_isascii(char c)      
 
643
{
 
644
  return (!(c & ~0177));
 
645
}
 
646
 
 
647
inline static char my_toascii(char c)
 
648
{
 
649
  return (c & 0177);
 
650
}
 
651
 
 
652
inline static char my_tocntrl(char c) 
 
653
{
 
654
  return (c & 31);
 
655
}
 
656
 
 
657
inline static char my_toprint(char c)
 
658
{
 
659
  return (c | 64);
 
660
}
 
661
 
 
662
inline static char my_toupper(const charset_info_st *s, unsigned char c)
 
663
{
 
664
  return s->to_upper[c];
 
665
}
 
666
 
 
667
inline static char my_tolower(const charset_info_st *s, unsigned char c)
 
668
{
 
669
  return s->to_lower[c];
 
670
}
 
671
 
 
672
inline static bool my_isalpha(const charset_info_st *s, unsigned char c)
 
673
{
 
674
  return (s->ctype+1)[c] & (_MY_U | _MY_L);
 
675
}
 
676
 
 
677
inline static bool my_isupper(const charset_info_st *s, unsigned char c)
 
678
{
 
679
  return (s->ctype+1)[c] & _MY_U;
 
680
}
 
681
 
 
682
inline static bool my_islower(const charset_info_st *s, unsigned char c)
 
683
{
 
684
  return (s->ctype+1)[c] & _MY_L;
 
685
}
 
686
 
 
687
inline static bool my_isdigit(const charset_info_st *s, unsigned char c)
 
688
{
 
689
  return (s->ctype+1)[c] & _MY_NMR;
 
690
}
 
691
 
 
692
inline static bool my_isxdigit(const charset_info_st *s, unsigned char c)
 
693
{
 
694
  return (s->ctype+1)[c] & _MY_X;
 
695
}
 
696
 
 
697
inline static bool my_isalnum(const charset_info_st *s, unsigned char c) 
 
698
{
 
699
  return (s->ctype+1)[c] & (_MY_U | _MY_L | _MY_NMR);
 
700
}
 
701
 
 
702
inline static bool my_isspace(const charset_info_st *s, unsigned char c)
 
703
{
 
704
  return (s->ctype+1)[c] & _MY_SPC;
 
705
}
 
706
 
 
707
inline static bool my_ispunct(const charset_info_st *s, unsigned char c)  
 
708
{
 
709
  return (s->ctype+1)[c] & _MY_PNT;
 
710
}
 
711
 
 
712
inline static bool my_isprint(const charset_info_st *s, unsigned char c)  
 
713
{
 
714
  return (s->ctype+1)[c] & (_MY_PNT | _MY_U | _MY_L | _MY_NMR | _MY_B);
 
715
}
 
716
 
 
717
inline static bool my_isgraph(const charset_info_st *s, unsigned char c)
 
718
{
 
719
  return (s->ctype+1)[c] & (_MY_PNT | _MY_U | _MY_L | _MY_NMR);
 
720
}
 
721
 
 
722
inline static bool my_iscntrl(const charset_info_st *s, unsigned char c)  
 
723
{
 
724
  return (s->ctype+1)[c] & _MY_CTR;
 
725
}
 
726
 
 
727
/* Some macros that should be cleaned up a little */
 
728
inline static bool my_isvar(const charset_info_st *s, char c)
 
729
{
 
730
  return my_isalnum(s,c) || (c) == '_';
 
731
}
 
732
 
 
733
inline static bool my_isvar_start(const charset_info_st *s, char c)
 
734
{
 
735
  return my_isalpha(s,c) || (c) == '_';
 
736
}
 
737
 
 
738
inline static bool my_binary_compare(const charset_info_st *s)
 
739
{
 
740
  return s->state  & MY_CS_BINSORT;
 
741
}
 
742
 
 
743
inline static bool use_strnxfrm(const charset_info_st *s)
 
744
{
 
745
  return s->state & MY_CS_STRNXFRM;
 
746
}
 
747
 
 
748
inline static size_t my_strnxfrm(const charset_info_st *cs, 
 
749
                                 unsigned char *dst, 
 
750
                                 const size_t dstlen, 
 
751
                                 const unsigned char *src, 
 
752
                                 const uint32_t srclen)
 
753
{
 
754
  return (cs->coll->strnxfrm(cs, dst, dstlen, dstlen, src, srclen, MY_STRXFRM_PAD_WITH_SPACE));
 
755
}
 
756
 
563
757
inline static int my_strnncoll(const charset_info_st *cs, 
564
758
                               const unsigned char *s, 
565
759
                               const size_t slen, 
591
785
  return (cs->coll->wildcmp(cs, str, strend, w_str, w_strend, escape, w_one, w_many));
592
786
}
593
787
 
 
788
inline static int my_strcasecmp(const charset_info_st *cs, const char *s, const char *t)
 
789
{
 
790
  return (cs->coll->strcasecmp(cs, s, t));
 
791
}
 
792
 
594
793
template <typename CHAR_T>
595
794
inline static size_t my_charpos(const charset_info_st *cs, 
596
795
                                const CHAR_T *b, const CHAR_T* e, size_t num)
614
813
}
615
814
 
616
815
 
 
816
inline static size_t my_caseup_str(const charset_info_st *cs, char *src)
 
817
{
 
818
  return cs->cset->caseup_str(cs, src);
 
819
}
 
820
 
 
821
inline static size_t my_casedn_str(const charset_info_st *cs, char *src)
 
822
{
 
823
  return cs->cset->casedn_str(cs, src);
 
824
}
 
825
 
617
826
inline static long my_strntol(const charset_info_st *cs, 
618
827
                              const char* s, const size_t l, const int base, char **e, int *err)
619
828
{
647
856
  return (cs->cset->strntod(cs, s, l, e, err));
648
857
}
649
858
 
650
 
int make_escape_code(const charset_info_st*, const char *escape);
 
859
int make_escape_code(const charset_info_st * const cs, const char *escape);
651
860
 
652
861
} /* namespace drizzled */
 
862