2002-10-23 12:40:22 +02:00
|
|
|
/* Copyright (C) 2002 MySQL AB & tommy@valley.ne.jp.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this library; if not, write to the Free
|
|
|
|
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
|
|
|
MA 02111-1307, USA */
|
|
|
|
|
|
|
|
/* This file is for binary pseudo charset, created by bar@mysql.com */
|
|
|
|
|
|
|
|
|
|
|
|
#include <my_global.h>
|
|
|
|
#include "m_string.h"
|
|
|
|
#include "m_ctype.h"
|
|
|
|
|
2003-02-12 20:55:37 +01:00
|
|
|
static uchar ctype_bin[]=
|
|
|
|
{
|
|
|
|
0,
|
|
|
|
32, 32, 32, 32, 32, 32, 32, 32, 32, 40, 40, 40, 40, 40, 32, 32,
|
|
|
|
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
|
|
|
|
72, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
2002-11-27 15:08:31 +01:00
|
|
|
132,132,132,132,132,132,132,132,132,132, 16, 16, 16, 16, 16, 16,
|
2003-02-12 20:55:37 +01:00
|
|
|
16,129,129,129,129,129,129, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 16, 16, 16, 16, 16,
|
|
|
|
16,130,130,130,130,130,130, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
|
|
|
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 16, 16, 16, 16, 32,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
2003-11-03 13:01:59 +01:00
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
2003-02-12 20:55:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Dummy array for toupper / tolower / sortorder */
|
|
|
|
|
|
|
|
static uchar bin_char_array[] =
|
|
|
|
{
|
|
|
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
|
|
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
|
|
|
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
|
|
|
|
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
|
|
|
|
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
|
|
|
|
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
|
|
|
|
96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
|
|
|
|
112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
|
|
|
|
128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
|
|
|
|
144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
|
|
|
|
160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
|
|
|
|
176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
|
|
|
|
192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
|
|
|
|
208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
|
|
|
|
224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
|
|
|
|
240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255
|
2002-11-27 15:08:31 +01:00
|
|
|
};
|
|
|
|
|
2002-10-23 12:40:22 +02:00
|
|
|
|
|
|
|
static int my_strnncoll_binary(CHARSET_INFO * cs __attribute__((unused)),
|
|
|
|
const uchar *s, uint slen,
|
|
|
|
const uchar *t, uint tlen)
|
|
|
|
{
|
2003-01-14 15:28:50 +01:00
|
|
|
int cmp= memcmp(s,t,min(slen,tlen));
|
|
|
|
return cmp ? cmp : (int) (slen - tlen);
|
2002-10-23 12:40:22 +02:00
|
|
|
}
|
|
|
|
|
2003-03-06 14:58:37 +01:00
|
|
|
static int my_strnncollsp_binary(CHARSET_INFO * cs,
|
|
|
|
const uchar *s, uint slen,
|
|
|
|
const uchar *t, uint tlen)
|
|
|
|
{
|
|
|
|
int len, cmp;
|
|
|
|
|
|
|
|
for ( ; slen && my_isspace(cs, s[slen-1]) ; slen--);
|
|
|
|
for ( ; tlen && my_isspace(cs, t[tlen-1]) ; tlen--);
|
|
|
|
|
|
|
|
len = ( slen > tlen ) ? tlen : slen;
|
|
|
|
|
|
|
|
cmp= memcmp(s,t,len);
|
|
|
|
return cmp ? cmp : (int) (slen - tlen);
|
|
|
|
}
|
|
|
|
|
2002-10-23 12:40:22 +02:00
|
|
|
static void my_caseup_str_bin(CHARSET_INFO *cs __attribute__((unused)),
|
|
|
|
char *str __attribute__((unused)))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void my_casedn_str_bin(CHARSET_INFO * cs __attribute__((unused)),
|
|
|
|
char *str __attribute__((unused)))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void my_caseup_bin(CHARSET_INFO * cs __attribute__((unused)),
|
|
|
|
char *str __attribute__((unused)),
|
|
|
|
uint length __attribute__((unused)))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void my_casedn_bin(CHARSET_INFO * cs __attribute__((unused)),
|
|
|
|
char *str __attribute__((unused)),
|
|
|
|
uint length __attribute__((unused)))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static int my_strcasecmp_bin(CHARSET_INFO * cs __attribute__((unused)),
|
|
|
|
const char *s, const char *t)
|
|
|
|
{
|
|
|
|
return strcmp(s,t);
|
|
|
|
}
|
|
|
|
|
2003-10-20 15:53:48 +02:00
|
|
|
int my_mbcharlen_8bit(CHARSET_INFO *cs __attribute__((unused)),
|
|
|
|
uint c __attribute__((unused)))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-10-23 12:40:22 +02:00
|
|
|
static int my_mb_wc_bin(CHARSET_INFO *cs __attribute__((unused)),
|
|
|
|
my_wc_t *wc,
|
|
|
|
const unsigned char *str,
|
|
|
|
const unsigned char *end __attribute__((unused)))
|
|
|
|
{
|
2003-01-27 13:46:03 +01:00
|
|
|
if (str >= end)
|
|
|
|
return MY_CS_TOOFEW(0);
|
|
|
|
|
2002-10-23 12:40:22 +02:00
|
|
|
*wc=str[0];
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int my_wc_mb_bin(CHARSET_INFO *cs __attribute__((unused)),
|
|
|
|
my_wc_t wc,
|
|
|
|
unsigned char *s,
|
|
|
|
unsigned char *e __attribute__((unused)))
|
|
|
|
{
|
2003-01-27 13:46:03 +01:00
|
|
|
if (s >= e)
|
|
|
|
return MY_CS_TOOSMALL;
|
|
|
|
|
2003-01-21 20:07:59 +01:00
|
|
|
if (wc < 256)
|
2002-10-23 12:40:22 +02:00
|
|
|
{
|
2003-01-21 20:07:59 +01:00
|
|
|
s[0]= (char) wc;
|
2002-10-23 12:40:22 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return MY_CS_ILUNI;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void my_hash_sort_bin(CHARSET_INFO *cs __attribute__((unused)),
|
|
|
|
const uchar *key, uint len,ulong *nr1, ulong *nr2)
|
|
|
|
{
|
|
|
|
const uchar *pos = key;
|
|
|
|
|
|
|
|
key+= len;
|
|
|
|
|
|
|
|
for (; pos < (uchar*) key ; pos++)
|
|
|
|
{
|
|
|
|
nr1[0]^=(ulong) ((((uint) nr1[0] & 63)+nr2[0]) *
|
|
|
|
((uint)*pos)) + (nr1[0] << 8);
|
|
|
|
nr2[0]+=3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-14 13:07:29 +01:00
|
|
|
static int my_wildcmp_bin(CHARSET_INFO *cs,
|
|
|
|
const char *str,const char *str_end,
|
|
|
|
const char *wildstr,const char *wildend,
|
|
|
|
int escape, int w_one, int w_many)
|
|
|
|
{
|
2003-03-06 13:51:37 +01:00
|
|
|
int result= -1; /* Not found, using wildcards */
|
2002-11-14 13:07:29 +01:00
|
|
|
|
|
|
|
while (wildstr != wildend)
|
|
|
|
{
|
|
|
|
while (*wildstr != w_many && *wildstr != w_one)
|
|
|
|
{
|
|
|
|
if (*wildstr == escape && wildstr+1 != wildend)
|
|
|
|
wildstr++;
|
|
|
|
if (str == str_end || *wildstr++ != *str++)
|
|
|
|
{
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
if (wildstr == wildend)
|
|
|
|
{
|
2003-03-06 13:51:37 +01:00
|
|
|
return(str != str_end); /* Match if both are at end */
|
2002-11-14 13:07:29 +01:00
|
|
|
}
|
2003-03-06 13:51:37 +01:00
|
|
|
result=1; /* Found an anchor char */
|
2002-11-14 13:07:29 +01:00
|
|
|
}
|
|
|
|
if (*wildstr == w_one)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2003-03-06 13:51:37 +01:00
|
|
|
if (str == str_end) /* Skip one char if possible */
|
2002-11-14 13:07:29 +01:00
|
|
|
return(result);
|
|
|
|
str++;
|
|
|
|
} while (*++wildstr == w_one && wildstr != wildend);
|
|
|
|
if (wildstr == wildend)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*wildstr == w_many)
|
2003-03-06 13:51:37 +01:00
|
|
|
{ /* Found w_many */
|
2002-11-14 13:07:29 +01:00
|
|
|
char cmp;
|
|
|
|
|
|
|
|
wildstr++;
|
|
|
|
/* Remove any '%' and '_' from the wild search string */
|
|
|
|
for (; wildstr != wildend ; wildstr++)
|
|
|
|
{
|
|
|
|
if (*wildstr == w_many)
|
|
|
|
continue;
|
|
|
|
if (*wildstr == w_one)
|
|
|
|
{
|
|
|
|
if (str == str_end)
|
|
|
|
{
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
str++;
|
|
|
|
continue;
|
|
|
|
}
|
2003-03-06 13:51:37 +01:00
|
|
|
break; /* Not a wild character */
|
2002-11-14 13:07:29 +01:00
|
|
|
}
|
|
|
|
if (wildstr == wildend)
|
|
|
|
{
|
2003-03-06 13:51:37 +01:00
|
|
|
return(0); /* Ok if w_many is last */
|
2002-11-14 13:07:29 +01:00
|
|
|
}
|
|
|
|
if (str == str_end)
|
|
|
|
{
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((cmp= *wildstr) == escape && wildstr+1 != wildend)
|
|
|
|
cmp= *++wildstr;
|
2003-03-06 13:51:37 +01:00
|
|
|
wildstr++; /* This is compared trough cmp */
|
2002-11-14 13:07:29 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
while (str != str_end && *str != cmp)
|
|
|
|
str++;
|
|
|
|
if (str++ == str_end)
|
|
|
|
{
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
int tmp=my_wildcmp_bin(cs,str,str_end,wildstr,wildend,escape,w_one,w_many);
|
|
|
|
if (tmp <= 0)
|
|
|
|
{
|
|
|
|
return(tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (str != str_end && wildstr[0] != w_many);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(str != str_end ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
2003-01-15 15:06:07 +01:00
|
|
|
static int my_strnxfrm_bin(CHARSET_INFO *cs __attribute__((unused)),
|
|
|
|
uchar * dest, uint len,
|
|
|
|
const uchar *src,
|
|
|
|
uint srclen __attribute__((unused)))
|
|
|
|
{
|
2003-04-01 09:45:16 +02:00
|
|
|
if (dest != src)
|
|
|
|
memcpy(dest,src,len= min(len,srclen));
|
2003-01-15 15:06:07 +01:00
|
|
|
return len;
|
|
|
|
}
|
2002-10-23 12:40:22 +02:00
|
|
|
|
2003-09-19 12:18:19 +02:00
|
|
|
static
|
2003-09-25 10:35:21 +02:00
|
|
|
uint my_instr_bin(CHARSET_INFO *cs __attribute__((unused)),
|
2003-10-21 11:58:43 +02:00
|
|
|
const char *b, uint b_length,
|
|
|
|
const char *s, uint s_length,
|
|
|
|
my_match_t *match, uint nmatch)
|
2003-09-19 12:18:19 +02:00
|
|
|
{
|
|
|
|
register const uchar *str, *search, *end, *search_end;
|
2003-10-20 15:53:48 +02:00
|
|
|
|
2003-09-19 12:18:19 +02:00
|
|
|
if (s_length <= b_length)
|
|
|
|
{
|
|
|
|
if (!s_length)
|
2003-09-25 10:35:21 +02:00
|
|
|
{
|
|
|
|
if (nmatch)
|
|
|
|
{
|
|
|
|
match->beg= 0;
|
|
|
|
match->end= 0;
|
|
|
|
match->mblen= 0;
|
|
|
|
}
|
|
|
|
return 1; /* Empty string is always found */
|
|
|
|
}
|
2003-10-20 15:53:48 +02:00
|
|
|
|
2003-10-15 14:34:28 +02:00
|
|
|
str= (const uchar*) b;
|
|
|
|
search= (const uchar*) s;
|
|
|
|
end= (const uchar*) b+b_length-s_length+1;
|
|
|
|
search_end= (const uchar*) s + s_length;
|
2003-10-20 15:53:48 +02:00
|
|
|
|
2003-09-19 12:18:19 +02:00
|
|
|
skipp:
|
|
|
|
while (str != end)
|
|
|
|
{
|
|
|
|
if ( (*str++) == (*search))
|
|
|
|
{
|
|
|
|
register const uchar *i,*j;
|
2003-10-20 15:53:48 +02:00
|
|
|
|
|
|
|
i= str;
|
2003-09-19 12:18:19 +02:00
|
|
|
j= search+1;
|
2003-10-20 15:53:48 +02:00
|
|
|
|
2003-09-19 12:18:19 +02:00
|
|
|
while (j != search_end)
|
|
|
|
if ((*i++) != (*j++))
|
|
|
|
goto skipp;
|
2003-10-20 15:53:48 +02:00
|
|
|
|
2003-09-25 10:35:21 +02:00
|
|
|
if (nmatch > 0)
|
|
|
|
{
|
|
|
|
match[0].beg= 0;
|
2003-10-15 14:34:28 +02:00
|
|
|
match[0].end= str- (const uchar*)b-1;
|
2003-09-25 10:35:21 +02:00
|
|
|
match[0].mblen= match[0].end;
|
2003-10-20 15:53:48 +02:00
|
|
|
|
2003-09-25 10:35:21 +02:00
|
|
|
if (nmatch > 1)
|
|
|
|
{
|
|
|
|
match[1].beg= match[0].end;
|
|
|
|
match[1].end= match[0].end+s_length;
|
|
|
|
match[1].mblen= match[1].end-match[1].beg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 2;
|
2003-09-19 12:18:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-09-25 10:35:21 +02:00
|
|
|
return 0;
|
2003-09-19 12:18:19 +02:00
|
|
|
}
|
|
|
|
|
2003-05-23 14:45:52 +02:00
|
|
|
|
2003-09-19 12:18:19 +02:00
|
|
|
MY_COLLATION_HANDLER my_collation_8bit_bin_handler =
|
2003-05-23 14:45:52 +02:00
|
|
|
{
|
|
|
|
my_strnncoll_binary,
|
|
|
|
my_strnncollsp_binary,
|
|
|
|
my_strnxfrm_bin,
|
|
|
|
my_like_range_simple,
|
|
|
|
my_wildcmp_bin,
|
|
|
|
my_strcasecmp_bin,
|
2003-09-19 12:18:19 +02:00
|
|
|
my_instr_bin,
|
2003-05-23 14:45:52 +02:00
|
|
|
my_hash_sort_bin
|
|
|
|
};
|
|
|
|
|
|
|
|
static MY_CHARSET_HANDLER my_charset_handler=
|
|
|
|
{
|
|
|
|
NULL, /* ismbchar */
|
2003-10-20 15:53:48 +02:00
|
|
|
my_mbcharlen_8bit, /* mbcharlen */
|
2003-05-23 14:45:52 +02:00
|
|
|
my_numchars_8bit,
|
|
|
|
my_charpos_8bit,
|
2003-09-16 12:43:17 +02:00
|
|
|
my_lengthsp_8bit,
|
2003-05-23 14:45:52 +02:00
|
|
|
my_mb_wc_bin,
|
|
|
|
my_wc_mb_bin,
|
|
|
|
my_caseup_str_bin,
|
|
|
|
my_casedn_str_bin,
|
|
|
|
my_caseup_bin,
|
|
|
|
my_casedn_bin,
|
|
|
|
my_snprintf_8bit,
|
|
|
|
my_long10_to_str_8bit,
|
|
|
|
my_longlong10_to_str_8bit,
|
|
|
|
my_fill_8bit,
|
|
|
|
my_strntol_8bit,
|
|
|
|
my_strntoul_8bit,
|
|
|
|
my_strntoll_8bit,
|
|
|
|
my_strntoull_8bit,
|
|
|
|
my_strntod_8bit,
|
|
|
|
my_scan_8bit
|
|
|
|
};
|
|
|
|
|
2003-01-29 14:31:20 +01:00
|
|
|
CHARSET_INFO my_charset_bin =
|
2002-10-23 12:40:22 +02:00
|
|
|
{
|
2003-03-05 13:43:10 +01:00
|
|
|
63,0,0, /* number */
|
2003-01-05 13:44:39 +01:00
|
|
|
MY_CS_COMPILED|MY_CS_BINSORT|MY_CS_PRIMARY,/* state */
|
2003-01-04 11:12:20 +01:00
|
|
|
"binary", /* cs name */
|
2002-10-23 12:40:22 +02:00
|
|
|
"binary", /* name */
|
|
|
|
"", /* comment */
|
2002-11-27 15:08:31 +01:00
|
|
|
ctype_bin, /* ctype */
|
2003-02-12 20:55:37 +01:00
|
|
|
bin_char_array, /* to_lower */
|
|
|
|
bin_char_array, /* to_upper */
|
|
|
|
bin_char_array, /* sort_order */
|
2002-10-23 12:40:22 +02:00
|
|
|
NULL, /* tab_to_uni */
|
|
|
|
NULL, /* tab_from_uni */
|
2003-03-14 15:08:12 +01:00
|
|
|
"","",
|
2003-08-18 14:24:50 +02:00
|
|
|
1, /* strxfrm_multiply */
|
2002-11-11 10:10:39 +01:00
|
|
|
1, /* mbmaxlen */
|
2003-01-21 20:07:59 +01:00
|
|
|
(char) 255, /* max_sort_char */
|
2003-05-23 14:45:52 +02:00
|
|
|
&my_charset_handler,
|
2003-09-19 12:18:19 +02:00
|
|
|
&my_collation_8bit_bin_handler
|
2002-10-23 12:40:22 +02:00
|
|
|
};
|