23 #include <drizzled/internal/m_string.h>
24 #include <drizzled/charset.h>
32 void my_hash_sort_bin(
const charset_info_st *
const,
33 const unsigned char *key,
size_t len,
34 uint32_t *nr1, uint32_t *nr2);
37 static unsigned char ctype_bin[]=
40 32, 32, 32, 32, 32, 32, 32, 32, 32, 40, 40, 40, 40, 40, 32, 32,
41 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
42 72, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
43 132,132,132,132,132,132,132,132,132,132, 16, 16, 16, 16, 16, 16,
44 16,129,129,129,129,129,129, 1, 1, 1, 1, 1, 1, 1, 1, 1,
45 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 16, 16, 16, 16, 16,
46 16,130,130,130,130,130,130, 2, 2, 2, 2, 2, 2, 2, 2, 2,
47 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 16, 16, 16, 16, 32,
48 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
49 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
50 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
51 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
52 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
53 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
54 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
55 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
61 static unsigned char bin_char_array[] =
63 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
64 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
65 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
66 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
67 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
68 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
69 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
70 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
71 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
72 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
73 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
74 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
75 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
76 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
77 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
78 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255
82 int my_strnncoll_binary(
const charset_info_st *
const,
83 const unsigned char *s,
size_t slen,
84 const unsigned char *t,
size_t tlen,
87 size_t len= min(slen,tlen);
88 int cmp= memcmp(s,t,len);
89 return cmp ? cmp :
static_cast<int>((t_is_prefix ? len : slen) - tlen);
93 size_t my_lengthsp_binary(
const charset_info_st *
const,
94 const char *,
size_t length)
122 int my_strnncollsp_binary(
const charset_info_st *
const cs,
123 const unsigned char *s,
size_t slen,
124 const unsigned char *t,
size_t tlen,
127 return my_strnncoll_binary(cs,s,slen,t,tlen,0);
131 int my_strnncoll_8bit_bin(
const charset_info_st *
const,
132 const unsigned char *s,
size_t slen,
133 const unsigned char *t,
size_t tlen,
136 size_t len= min(slen,tlen);
137 int cmp= memcmp(s,t,len);
138 return cmp ? cmp :
static_cast<int>((t_is_prefix ? len : slen) - tlen);
167 int my_strnncollsp_8bit_bin(
const charset_info_st *
const,
168 const unsigned char *a,
size_t a_length,
169 const unsigned char *b,
size_t b_length,
170 bool diff_if_only_endspace_difference)
172 const unsigned char *end;
176 #ifndef VARCHAR_WITH_DIFF_ENDSPACE_ARE_DIFFERENT_FOR_UNIQUE
177 diff_if_only_endspace_difference= 0;
180 end= a + (length= min(a_length, b_length));
184 return a[-1] - b[-1];
187 if (a_length != b_length)
194 if (diff_if_only_endspace_difference)
196 if (a_length < b_length)
204 for (end= a + a_length-length; a < end ; a++)
207 return (*a <
' ') ? -swap : swap;
216 size_t my_case_str_bin(
const charset_info_st *
const,
char *)
222 size_t my_case_bin(
const charset_info_st *
const,
char *,
223 size_t srclen,
char *,
size_t)
229 int my_strcasecmp_bin(
const charset_info_st *
const,
230 const char *s,
const char *t)
236 uint32_t my_mbcharlen_8bit(
const charset_info_st *
const, uint32_t)
242 int my_mb_wc_bin(
const charset_info_st *
const,
243 my_wc_t *wc,
const unsigned char *str,
244 const unsigned char *end)
247 return MY_CS_TOOSMALL;
254 int my_wc_mb_bin(
const charset_info_st *
const, my_wc_t wc,
255 unsigned char *str,
unsigned char *end)
258 return MY_CS_TOOSMALL;
269 void my_hash_sort_8bit_bin(
const charset_info_st *
const,
270 const unsigned char *key,
size_t len,
271 uint32_t *nr1, uint32_t *nr2)
273 const unsigned char *pos = key;
279 key= internal::skip_trailing_space(key, len);
281 for (; pos < key ; pos++)
283 nr1[0]^= (((nr1[0] & 63) + nr2[0]) * *pos) + (nr1[0] << 8);
289 void my_hash_sort_bin(
const charset_info_st *
const,
290 const unsigned char *key,
size_t len,
291 uint32_t *nr1, uint32_t *nr2)
293 const unsigned char *pos = key;
297 for (; pos < key ; pos++)
299 nr1[0]^= (((nr1[0] & 63) + nr2[0]) * *pos) + (nr1[0] << 8);
310 #define likeconv(s,A) (A)
311 #define INC_PTR(cs,A,B) (A)++
314 int my_wildcmp_bin(
const charset_info_st *
const cs,
315 const char *str,
const char *str_end,
316 const char *wildstr,
const char *wildend,
317 int escape,
int w_one,
int w_many)
321 while (wildstr != wildend)
323 while (*wildstr != w_many && *wildstr != w_one)
325 if (*wildstr == escape && wildstr+1 != wildend)
327 if (str == str_end || likeconv(cs,*wildstr++) != likeconv(cs,*str++))
329 if (wildstr == wildend)
330 return(str != str_end);
333 if (*wildstr == w_one)
339 INC_PTR(cs,str,str_end);
340 }
while (++wildstr < wildend && *wildstr == w_one);
341 if (wildstr == wildend)
344 if (*wildstr == w_many)
349 for (; wildstr != wildend ; wildstr++)
351 if (*wildstr == w_many)
353 if (*wildstr == w_one)
357 INC_PTR(cs,str,str_end);
362 if (wildstr == wildend)
367 if ((cmp= *wildstr) == escape && wildstr+1 != wildend)
370 INC_PTR(cs,wildstr,wildend);
371 cmp=likeconv(cs,cmp);
374 while (str != str_end && (
unsigned char) likeconv(cs,*str) != cmp)
376 if (str++ == str_end)
379 int tmp=my_wildcmp_bin(cs,str,str_end,wildstr,wildend,escape,w_one,
384 }
while (str != str_end && wildstr[0] != w_many);
388 return(str != str_end ? 1 : 0);
393 my_strnxfrm_8bit_bin(
const charset_info_st *
const cs,
394 unsigned char * dst,
size_t dstlen, uint32_t nweights,
395 const unsigned char *src,
size_t srclen, uint32_t flags)
397 set_if_smaller(srclen, dstlen);
398 set_if_smaller(srclen, (
size_t) nweights);
400 memcpy(dst, src, srclen);
401 return my_strxfrm_pad_desc_and_reverse(cs, dst, dst + srclen, dst + dstlen,
402 nweights - srclen, flags, 0);
406 uint32_t my_instr_bin(
const charset_info_st *
const,
407 const char *b,
size_t b_length,
408 const char *s,
size_t s_length,
409 my_match_t *match, uint32_t nmatch)
411 const unsigned char *str, *search, *end, *search_end;
413 if (s_length <= b_length)
426 str= (
const unsigned char*) b;
427 search= (
const unsigned char*) s;
428 end= (
const unsigned char*) b+b_length-s_length+1;
429 search_end= (
const unsigned char*) s + s_length;
434 if ( (*str++) == (*search))
436 const unsigned char *i,*j;
441 while (j != search_end)
442 if ((*i++) != (*j++))
448 match[0].end= (size_t) (str- (
const unsigned char*)b-1);
449 match[0].mb_len= match[0].end;
453 match[1].beg= match[0].end;
454 match[1].end= match[0].end+s_length;
455 match[1].mb_len= match[1].end-match[1].beg;
466 static MY_COLLATION_HANDLER my_collation_binary_handler =
470 my_strnncollsp_binary,
471 my_strnxfrm_8bit_bin,
472 my_strnxfrmlen_simple,
473 my_like_range_simple,
482 static MY_CHARSET_HANDLER my_charset_handler=
488 my_well_formed_len_8bit,
499 my_long10_to_str_8bit,
500 my_int64_t10_to_str_8bit,
508 my_strntoull10rnd_8bit,
516 MY_CS_COMPILED|MY_CS_BINSORT|MY_CS_PRIMARY,
543 &my_collation_binary_handler
TODO: Rename this file - func.h is stupid.