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"
|
|
|
|
|
2002-11-27 15:08:31 +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,
|
|
|
|
132,132,132,132,132,132,132,132,132,132, 16, 16, 16, 16, 16, 16,
|
|
|
|
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,
|
|
|
|
72, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
|
|
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 16, 1, 1, 1, 1, 1, 1, 1, 2,
|
|
|
|
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
|
|
|
2, 2, 2, 2, 2, 2, 2, 16, 2, 2, 2, 2, 2, 2, 2, 2
|
|
|
|
};
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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 void my_tosort_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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int my_strncasecmp_bin(CHARSET_INFO * cs __attribute__((unused)),
|
|
|
|
const char *s, const char *t, uint len)
|
|
|
|
{
|
|
|
|
return memcmp(s,t,len);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef NEW_HASH_FUNCTION
|
|
|
|
|
|
|
|
/* Calc hashvalue for a key, case indepenently */
|
|
|
|
|
|
|
|
static uint my_hash_caseup_bin(CHARSET_INFO *cs __attribute__((unused)),
|
|
|
|
const byte *key, uint length)
|
|
|
|
{
|
|
|
|
register uint nr=1, nr2=4;
|
|
|
|
|
|
|
|
while (length--)
|
|
|
|
{
|
|
|
|
nr^= (((nr & 63)+nr2)*
|
|
|
|
((uint) (uchar) *key++)) + (nr << 8);
|
|
|
|
nr2+=3;
|
|
|
|
}
|
|
|
|
return((uint) nr);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
static uint my_hash_caseup_bin(CHARSET_INFO *cs __attribute__((unused)),
|
|
|
|
const byte *key, uint len)
|
|
|
|
{
|
|
|
|
const byte *end=key+len;
|
|
|
|
uint hash;
|
|
|
|
for (hash = 0; key < end; key++)
|
|
|
|
{
|
|
|
|
hash *= 16777619;
|
|
|
|
hash ^= (uint) (uchar) *key;
|
|
|
|
}
|
|
|
|
return (hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
int result= -1; // Not found, using wildcards
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
return(str != str_end); // Match if both are at end
|
|
|
|
}
|
|
|
|
result=1; // Found an anchor char
|
|
|
|
}
|
|
|
|
if (*wildstr == w_one)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (str == str_end) // Skip one char if possible
|
|
|
|
return(result);
|
|
|
|
str++;
|
|
|
|
} while (*++wildstr == w_one && wildstr != wildend);
|
|
|
|
if (wildstr == wildend)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*wildstr == w_many)
|
|
|
|
{ // Found w_many
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
break; // Not a wild character
|
|
|
|
}
|
|
|
|
if (wildstr == wildend)
|
|
|
|
{
|
|
|
|
return(0); // Ok if w_many is last
|
|
|
|
}
|
|
|
|
if (str == str_end)
|
|
|
|
{
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((cmp= *wildstr) == escape && wildstr+1 != wildend)
|
|
|
|
cmp= *++wildstr;
|
|
|
|
wildstr++; // This is compared trough cmp
|
|
|
|
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)))
|
|
|
|
{
|
|
|
|
memcpy(dest,src,len= min(len,srclen));
|
|
|
|
return len;
|
|
|
|
}
|
2002-10-23 12:40:22 +02:00
|
|
|
|
2002-10-23 15:20:45 +02:00
|
|
|
static CHARSET_INFO my_charset_bin_st =
|
2002-10-23 12:40:22 +02:00
|
|
|
{
|
2002-11-14 13:07:29 +01:00
|
|
|
63, /* 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 */
|
2002-10-23 12:40:22 +02:00
|
|
|
NULL, /* to_lower */
|
|
|
|
NULL, /* to_upper */
|
|
|
|
NULL, /* sort_order */
|
|
|
|
NULL, /* tab_to_uni */
|
|
|
|
NULL, /* tab_from_uni */
|
|
|
|
0, /* strxfrm_multiply */
|
|
|
|
my_strnncoll_binary, /* strnncoll */
|
2003-01-15 15:06:07 +01:00
|
|
|
my_strnxfrm_bin, /* strxnfrm */
|
2002-11-15 08:44:23 +01:00
|
|
|
my_like_range_simple, /* like_range */
|
2002-11-14 13:07:29 +01:00
|
|
|
my_wildcmp_bin, /* wildcmp */
|
2002-11-11 10:10:39 +01:00
|
|
|
1, /* mbmaxlen */
|
2002-10-23 12:40:22 +02:00
|
|
|
NULL, /* ismbchar */
|
|
|
|
NULL, /* ismbhead */
|
|
|
|
NULL, /* mbcharlen */
|
|
|
|
my_mb_wc_bin, /* mb_wc */
|
|
|
|
my_wc_mb_bin, /* wc_mb */
|
|
|
|
my_caseup_str_bin, /* caseup_str */
|
|
|
|
my_casedn_str_bin, /* casedn_str */
|
|
|
|
my_caseup_bin, /* caseup */
|
|
|
|
my_casedn_bin, /* casedn */
|
|
|
|
my_tosort_bin, /* tosort */
|
|
|
|
my_strcasecmp_bin, /* strcasecmp */
|
|
|
|
my_strncasecmp_bin, /* strncasecmp */
|
|
|
|
my_hash_caseup_bin, /* hash_caseup */
|
|
|
|
my_hash_sort_bin, /* hash_sort */
|
2003-01-21 20:07:59 +01:00
|
|
|
(char) 255, /* max_sort_char */
|
2002-11-14 13:07:29 +01:00
|
|
|
my_snprintf_8bit, /* snprintf */
|
2003-01-15 15:06:07 +01:00
|
|
|
my_long10_to_str_8bit,
|
|
|
|
my_longlong10_to_str_8bit,
|
2002-11-27 12:47:39 +01:00
|
|
|
my_strntol_8bit,
|
|
|
|
my_strntoul_8bit,
|
|
|
|
my_strntoll_8bit,
|
|
|
|
my_strntoull_8bit,
|
2002-12-11 09:30:05 +01:00
|
|
|
my_strntod_8bit,
|
2003-01-17 15:14:54 +01:00
|
|
|
my_scan_8bit
|
2002-10-23 12:40:22 +02:00
|
|
|
};
|
|
|
|
|
2002-10-23 15:20:45 +02:00
|
|
|
|
|
|
|
CHARSET_INFO *my_charset_bin = &my_charset_bin_st;
|