mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 13:02:28 +01:00
a8ea31fae6
Renamed HA_VAR_LENGTH to HA_VAR_LENGTH_PART Renamed in all files FIELD_TYPE_STRING and FIELD_TYPE_VAR_STRING to MYSQL_TYPE_STRING and MYSQL_TYPE_VAR_STRING to make it easy to catch all possible errors Added support for VARCHAR KEYS to heap Removed support for ISAM Now only long VARCHAR columns are changed to TEXT on demand (not CHAR) Internal temporary files can now use fixed length tables if the used VARCHAR columns are short BitKeeper/deleted/.del-ha_isam.cc~4dce65904db2675e: Delete: sql/ha_isam.cc BitKeeper/deleted/.del-_cache.c~b5d80b5c3ae233b1: Delete: isam/_cache.c BitKeeper/deleted/.del-_dbug.c~88d7964ae5e3c9bd: Delete: isam/_dbug.c BitKeeper/deleted/.del-_dynrec.c~48dd758f5a5450df: Delete: isam/_dynrec.c BitKeeper/deleted/.del-_key.c~ce62d47a6c681084: Delete: isam/_key.c BitKeeper/deleted/.del-_locking.c~dea4cdc6ea425c67: Delete: isam/_locking.c BitKeeper/deleted/.del-_packrec.c~47ae1b16c007e9be: Delete: isam/_packrec.c BitKeeper/deleted/.del-_page.c~148b1a613d052ee8: Delete: isam/_page.c BitKeeper/deleted/.del-_search.c~f509292aa1ff18ff: Delete: isam/_search.c BitKeeper/deleted/.del-_statrec.c~58d9263b3475d58b: Delete: isam/_statrec.c BitKeeper/deleted/.del-changed.c~d075de80a314b02d: Delete: isam/changed.c BitKeeper/deleted/.del-close.c~fd62629496ee5bcc: Delete: isam/close.c BitKeeper/deleted/.del-create.c~96cecc433c0c2242: Delete: isam/create.c BitKeeper/deleted/.del-delete.c~65ee8daaa75a14b6: Delete: isam/delete.c BitKeeper/deleted/.del-extra.c~706f29d72beb2565: Delete: isam/extra.c BitKeeper/deleted/.del-info.c~96cfb747af8da0d: Delete: isam/info.c BitKeeper/deleted/.del-isamchk.c~c0f59c2687d2248f: Delete: isam/isamchk.c BitKeeper/deleted/.del-isamlog.c~85b6b31c6e2b8519: Delete: isam/isamlog.c BitKeeper/deleted/.del-log.c~55a973013d55cade: Delete: isam/log.c BitKeeper/deleted/.del-open.c~95b3b75042fae00a: Delete: isam/open.c BitKeeper/deleted/.del-pack_isam.c~43801f0df7504834: Delete: isam/pack_isam.c BitKeeper/deleted/.del-panic.c~f7fd71605324f8f3: Delete: isam/panic.c BitKeeper/deleted/.del-range.c~142f1f8ac4948082: Delete: isam/range.c BitKeeper/deleted/.del-rfirst.c~66f494291dc005d3: Delete: isam/rfirst.c BitKeeper/deleted/.del-rkey.c~cc54c6498352f999: Delete: isam/rkey.c BitKeeper/deleted/.del-rlast.c~d1fe1866139e9866: Delete: isam/rlast.c BitKeeper/deleted/.del-rnext.c~b308eaa1e11ea7de: Delete: isam/rnext.c BitKeeper/deleted/.del-rprev.c~b359f71fdea4bbce: Delete: isam/rprev.c BitKeeper/deleted/.del-rrnd.c~7fcfcce88d4a5200: Delete: isam/rrnd.c BitKeeper/deleted/.del-rsame.c~75a62d5548103a15: Delete: isam/rsame.c BitKeeper/deleted/.del-rsamepos.c~5b5652dd2cda6d5d: Delete: isam/rsamepos.c BitKeeper/deleted/.del-sort.c~e2e56b5a37ce86f4: Delete: isam/sort.c BitKeeper/deleted/.del-static.c~3a1354b84f4a9cc7: Delete: isam/static.c BitKeeper/deleted/.del-test1.c~64d52e9412d457ed: Delete: isam/test1.c BitKeeper/deleted/.del-test2.c~2f9a632cab572958: Delete: isam/test2.c BitKeeper/deleted/.del-test3.c~e8a7a4afe8a087: Delete: isam/test3.c BitKeeper/deleted/.del-isamdef.h~ac8d49e7e2201c66: Delete: isam/isamdef.h BitKeeper/deleted/.del-update.c~670264f51dc44934: Delete: isam/update.c BitKeeper/deleted/.del-write.c~8f1918b1f6770e54: Delete: isam/write.c BitKeeper/deleted/.del-Makefile.am~6cfa0db5e7778d09: Delete: isam/Makefile.am BitKeeper/deleted/.del-make-ccc~3ee55391eda0b0ab: Delete: isam/make-ccc BitKeeper/deleted/.del-ChangeLog~208984fb7a51e568: Delete: isam/ChangeLog BitKeeper/deleted/.del-test_all.res~c2aafb49a3a77db7: Delete: isam/test_all.res BitKeeper/deleted/.del-test_all~93c701e44a9c5b65: Delete: isam/test_all BitKeeper/deleted/.del-.cvsignore~54f6f0f2d5012561: Delete: isam/.cvsignore BitKeeper/deleted/.del-ha_isammrg.cc~dc682e4755d77a2e: Delete: sql/ha_isammrg.cc BitKeeper/deleted/.del-ha_isam.h~bf53d533be3d3927: Delete: sql/ha_isam.h BitKeeper/deleted/.del-ha_isammrg.h~66fd2e5bfe7207dc: Delete: sql/ha_isammrg.h acinclude.m4: Remove ISAM client/mysqldump.c: FIELD_TYPE -> MYSQL_TYPE client/mysqltest.c: Add missing DBUG_RETURN configure.in: Remove ISAM heap/heapdef.h: Add support for VARCHAR heap/hp_create.c: Add support for VARCHAR heap/hp_delete.c: Add support for VARCHAR heap/hp_hash.c: Add support for VARCHAR (VARCHAR keys was not supported before) heap/hp_rkey.c: Add support for VARCHAR heap/hp_update.c: Add support for VARCHAR heap/hp_write.c: Add support for VARCHAR (Added flag SEARCH_UPDATE to mark that this is an update) include/decimal.h: Remove not needed my_global.h include/m_ctype.h: Add support for VARCHAR include/my_base.h: Add support for VARCHAR include/my_handler.h: Moved general purpose macro from MyISAM code include/mysql_com.h: Add support for VARCHAR libmysql/libmysql.c: Add support for VARCHAR libmysqld/Makefile.am: Removed ISAM myisam/ft_static.c: Add support for VARCHAR myisam/ft_test1.c: Add support for VARCHAR myisam/ft_update.c: Add support for VARCHAR myisam/mi_check.c: Add support for VARCHAR myisam/mi_create.c: Add support for VARCHAR - VARCHAR key segments are marked with HA_VAR_LENGTH_PART myisam/mi_key.c: Add support for VARCHAR Fixed bug in old VARCHAR code when reading index-only myisam/mi_range.c: Fixed comment style myisam/mi_rnext_same.c: Handle case where equal keys can be of different length myisam/mi_search.c: Add support for VARCHAR myisam/mi_test1.c: Add support for VARCHAR myisam/mi_unique.c: Add support for VARCHAR (Some new code to handle keys that are equal but have different lengths) myisam/mi_write.c: Fixed comment myisam/myisamchk.c: Better infotext if wrong type mysql-test/r/bdb.result: Updated old result and new results for VARCHAR mysql-test/r/create.result: Updated old result and new results for VARCHAR mysql-test/r/ctype_tis620.result: Updated old result and new results for VARCHAR (Old code sorted tis620 wrong) mysql-test/r/ctype_ucs.result: Updated old result and new results for VARCHAR mysql-test/r/endspace.result: Updated old result and new results for VARCHAR mysql-test/r/func_like.result: Updated old result and new results for VARCHAR mysql-test/r/heap.result: Updated old result and new results for VARCHAR mysql-test/r/innodb.result: Updated old result. This will change a bit when also InnoDB supports VARCHAR mysql-test/r/merge.result: Updated old result and new results for VARCHAR mysql-test/r/myisam.result: Updated old result and new results for VARCHAR mysql-test/r/mysqldump.result: Updated old result and new results for VARCHAR mysql-test/r/order_by.result: Updated old result and new results for VARCHAR (Key length is different for VARCHAR) mysql-test/r/ps.result: Updated old result and new results for VARCHAR mysql-test/r/ps_1general.result: Updated results for new .frm version Don't print seconds in show full process list as this may change mysql-test/r/ps_2myisam.result: Updated old result and new results for VARCHAR mysql-test/r/ps_3innodb.result: Updated old result and new results for VARCHAR mysql-test/r/ps_4heap.result: Updated old result and new results for VARCHAR mysql-test/r/ps_5merge.result: Updated old result and new results for VARCHAR mysql-test/r/ps_6bdb.result: Updated old result and new results for VARCHAR mysql-test/r/select.result.es: Updated results by hand mysql-test/r/select.result: Updated old result and new results for VARCHAR mysql-test/r/select_found.result: Updated old result and new results for VARCHAR mysql-test/r/show_check.result: Updated old result and new results for VARCHAR mysql-test/r/strict.result: Updated old result and new results for VARCHAR mysql-test/r/subselect.result: Updated old result and new results for VARCHAR mysql-test/r/system_mysql_db.result: Updated old result and new results for VARCHAR mysql-test/r/type_blob.result: Updated old result and new results for VARCHAR mysql-test/r/type_ranges.result: Updated old result and new results for VARCHAR mysql-test/r/type_ranges.result.es: Updated some results by hand mysql-test/t/bdb.test: Test VARCHAR mysql-test/t/ctype_ucs.test: Some fixes related to VARCHAR mysql-test/t/endspace.test: Fixes to make it easier to compare columns with end space mysql-test/t/heap.test: Test VARCHAR mysql-test/t/innodb.test: Prepare for testing VARCHAR mysql-test/t/myisam.test: Test VARCHAR mysql-test/t/ps_1general.test: Don't show seconds for show processlist mysql-test/t/ps_4heap.test: Update for VARCHAR mysql-test/t/strict.test: Fix test for VARCHAR mysql-test/t/type_blob.test: Update test for VARCHAR Note that now you can't store 'a' and 'a ' in an unique varchar/text index if the column is not binary mysys/my_handler.c: Add support for VARCHAR ndb/src/common/util/NdbSqlUtil.cpp: Fix for usage of strnncollsp scripts/mysql_fix_privilege_tables.sh: Simple fix so that my_print_defaults works sql/Makefile.am: Remove ISAM sql/field.cc: Add support for VARCHAR Fixed the keys for blob's are compared with strnncollsp Ensure that old tables from MySQL 4.0 works as they did before. (Old VARCHAR will be converted to new VARCHAR on ALTER TABLE) sql/field.h: Add support for VARCHAR sql/field_conv.cc: Change FIELD_TYPE_VAR_STRING -> MYSQL_TYPE_VARCHAR Added usage of HA_KEY_BLOB_LENGTH sql/ha_berkeley.cc: Add support for VARCHAR Added usage of table->insert_or_update if we would ever want to know in key_cmp if we are changing keys sql/ha_heap.cc: Add support for VARCHAR sql/ha_innodb.cc: Changed MYSQL_TYPE_VAR_STRING to MYSQL_TYPE_VARCHAR. Waiting for Heikki to add full VARCHAR support sql/ha_innodb.h: InnoDB doesn't support full VARCHAR yet sql/ha_myisam.cc: Add support for VARCHAR sql/ha_ndbcluster.cc: Add support for VARCHAR sql/handler.h: Added HA_NO_VARCHAR for table handler that doesn't support VARCHAR. In this case MySQL will create a normal CHAR instead sql/item.cc: Fixed access of already freed memory Added support of VARCHAR - varchar length is now checked in mysql_prepare sql/item_cmpfunc.cc: Added new parameter to strncollsp sql/item_sum.cc: Added new parameter to strncollsp FIELD_TYPE -> MYSQL_TYPE sql/key.cc: Add support for VARCHAR sql/opt_range.cc: Remove character set parameter from set_key_image() sql/opt_sum.cc: Remove character set parameter from set_key_image() sql/protocol.cc: Return MYSQL_TYPE_VAR_STRING instead of MYSQL_TYPE_VARCHAR to clients (to not cause compatiblity problems) sql/sql_acl.cc: Change key handling code so that we can use CHAR or VARCHAR for the user table columns sql/sql_base.cc: Remove old, not used code sql/sql_help.cc: Remove charset from get_key_image sql/sql_parse.cc: Ensure that OPTION_TABLE_LOCK is cleared ASAP; This fixed a problem in BDB transaction code when one used LOCK TABLES on a BDB table Added support for VARCHAR Moved field length checking and VARCHAR -> TEXT convert to mysql_prepare (as we need the know the character set for the column) sql/sql_select.cc: Added support of VARCHAR Added heuristic to use fixed size rows for tmp tables if we are using only a few short VARCHAR's sql/sql_string.cc: Added extra argument to strnncollsp sql/sql_table.cc: Add support for VARCHAR Automaticly convert (with warning) big VARCHAR (but not CHAR) to TEXT If handler doesn't support VARCHAR convert VARCHAR to CHAR sql/sql_update.cc: Fixed compiler warning sql/sql_yacc.yy: Add support for VARCHAR sql/strfunc.cc: Fixed valgrind warning sql/structs.h: Added 'table' to KEY structure to make life easier for some handler functions sql/table.cc: Add support for VARCHAR - New .frm version - FIELD_TYPE -> MYSQL_TYPE sql/table.h: Added insert_or_update; A bool flag a handler can set/reset if needed (for handler internal usage) sql/unireg.h: Add support for VARCHAR strings/ctype-big5.c: Added new argument to strnncollsp() to allow one to define if end space are significant or not Changed my_like_range... to correctly calculate min_length & max_length strings/ctype-bin.c: Added new argument to strnncollsp() to allow one to define if end space are significant or not strings/ctype-czech.c: Changed my_like_range... to correctly calculate min_length & max_length strings/ctype-gbk.c: Added new argument to strnncollsp() to allow one to define if end space are significant or not Changed my_like_range... to correctly calculate min_length & max_length strings/ctype-latin1.c: Added new argument to strnncollsp() to allow one to define if end space are significant or not strings/ctype-mb.c: Added new argument to strnncollsp() to allow one to define if end space are significant or not Changed my_like_range... to correctly calculate min_length & max_length strings/ctype-simple.c: Added new argument to strnncollsp() to allow one to define if end space are significant or not Changed my_like_range... to correctly calculate min_length & max_length strings/ctype-sjis.c: Added new argument to strnncollsp() to allow one to define if end space are significant or not Changed my_like_range... to correctly calculate min_length & max_length strings/ctype-tis620.c: Added new argument to strnncollsp() to allow one to define if end space are significant or not Changed my_like_range... to correctly calculate min_length & max_length strings/ctype-uca.c: Added new argument to strnncollsp() to allow one to define if end space are significant or not strings/ctype-ucs2.c: Changed my_like_range... to correctly calculate min_length & max_length strings/ctype-utf8.c: Added new argument to strnncollsp() to allow one to define if end space are significant or not strings/ctype-win1250ch.c: Changed my_like_range... to correctly calculate min_length & max_length strings/decimal.c: Fixed include files usage Fixed some compiler warnings tests/client_test.c: Ensure tests works with VARCHAR
1353 lines
27 KiB
C
1353 lines
27 KiB
C
/* Copyright (C) 2002 MySQL AB
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program 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 General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
#include <my_global.h>
|
|
#include "m_string.h"
|
|
#include "m_ctype.h"
|
|
#include <errno.h>
|
|
|
|
#include "stdarg.h"
|
|
|
|
|
|
int my_strnxfrm_simple(CHARSET_INFO * cs,
|
|
uchar *dest, uint len,
|
|
const uchar *src, uint srclen)
|
|
{
|
|
uchar *map= cs->sort_order;
|
|
set_if_smaller(len, srclen);
|
|
if (dest != src)
|
|
{
|
|
const uchar *end;
|
|
for ( end=src+len; src < end ; )
|
|
*dest++= map[*src++];
|
|
return len;
|
|
}
|
|
else
|
|
{
|
|
const uchar *end;
|
|
for ( end=dest+len; dest < end ; dest++)
|
|
*dest= (char) map[(uchar) *dest];
|
|
return len;
|
|
}
|
|
}
|
|
|
|
int my_strnncoll_simple(CHARSET_INFO * cs, const uchar *s, uint slen,
|
|
const uchar *t, uint tlen,
|
|
my_bool t_is_prefix)
|
|
{
|
|
int len = ( slen > tlen ) ? tlen : slen;
|
|
uchar *map= cs->sort_order;
|
|
if (t_is_prefix && slen > tlen)
|
|
slen=tlen;
|
|
while (len--)
|
|
{
|
|
if (map[*s++] != map[*t++])
|
|
return ((int) map[s[-1]] - (int) map[t[-1]]);
|
|
}
|
|
return (int) (slen - tlen);
|
|
}
|
|
|
|
|
|
/*
|
|
Compare strings, discarding end space
|
|
|
|
SYNOPSIS
|
|
my_strnncollsp_simple()
|
|
cs character set handler
|
|
a First string to compare
|
|
a_length Length of 'a'
|
|
b Second string to compare
|
|
b_length Length of 'b'
|
|
diff_if_only_endspace_difference
|
|
Set to 1 if the strings should be regarded as different
|
|
if they only difference in end space
|
|
|
|
IMPLEMENTATION
|
|
If one string is shorter as the other, then we space extend the other
|
|
so that the strings have equal length.
|
|
|
|
This will ensure that the following things hold:
|
|
|
|
"a" == "a "
|
|
"a\0" < "a"
|
|
"a\0" < "a "
|
|
|
|
RETURN
|
|
< 0 a < b
|
|
= 0 a == b
|
|
> 0 a > b
|
|
*/
|
|
|
|
int my_strnncollsp_simple(CHARSET_INFO * cs, const uchar *a, uint a_length,
|
|
const uchar *b, uint b_length,
|
|
my_bool diff_if_only_endspace_difference)
|
|
{
|
|
const uchar *map= cs->sort_order, *end;
|
|
uint length;
|
|
int res;
|
|
|
|
#ifndef VARCHAR_WITH_DIFF_ENDSPACE_ARE_DIFFERENT_FOR_UNIQUE
|
|
diff_if_only_endspace_difference= 0;
|
|
#endif
|
|
|
|
end= a + (length= min(a_length, b_length));
|
|
while (a < end)
|
|
{
|
|
if (map[*a++] != map[*b++])
|
|
return ((int) map[a[-1]] - (int) map[b[-1]]);
|
|
}
|
|
res= 0;
|
|
if (a_length != b_length)
|
|
{
|
|
int swap= 0;
|
|
if (diff_if_only_endspace_difference)
|
|
res= 1; /* Assume 'a' is bigger */
|
|
/*
|
|
Check the next not space character of the longer key. If it's < ' ',
|
|
then it's smaller than the other key.
|
|
*/
|
|
if (a_length < b_length)
|
|
{
|
|
/* put shorter key in s */
|
|
a_length= b_length;
|
|
a= b;
|
|
swap= -1; /* swap sign of result */
|
|
res= -res;
|
|
}
|
|
for (end= a + a_length-length; a < end ; a++)
|
|
{
|
|
if (*a != ' ')
|
|
return ((int) *a - (int) ' ') ^ swap;
|
|
}
|
|
}
|
|
return res;
|
|
}
|
|
|
|
|
|
void my_caseup_str_8bit(CHARSET_INFO * cs,char *str)
|
|
{
|
|
register uchar *map=cs->to_upper;
|
|
while ((*str = (char) map[(uchar) *str]) != 0)
|
|
str++;
|
|
}
|
|
|
|
void my_casedn_str_8bit(CHARSET_INFO * cs,char *str)
|
|
{
|
|
register uchar *map=cs->to_lower;
|
|
while ((*str = (char) map[(uchar)*str]) != 0)
|
|
str++;
|
|
}
|
|
|
|
void my_caseup_8bit(CHARSET_INFO * cs, char *str, uint length)
|
|
{
|
|
register uchar *map=cs->to_upper;
|
|
for ( ; length>0 ; length--, str++)
|
|
*str= (char) map[(uchar)*str];
|
|
}
|
|
|
|
void my_casedn_8bit(CHARSET_INFO * cs, char *str, uint length)
|
|
{
|
|
register uchar *map=cs->to_lower;
|
|
for ( ; length>0 ; length--, str++)
|
|
*str= (char) map[(uchar) *str];
|
|
}
|
|
|
|
int my_strcasecmp_8bit(CHARSET_INFO * cs,const char *s, const char *t)
|
|
{
|
|
register uchar *map=cs->to_upper;
|
|
while (map[(uchar) *s] == map[(uchar) *t++])
|
|
if (!*s++) return 0;
|
|
return ((int) map[(uchar) s[0]] - (int) map[(uchar) t[-1]]);
|
|
}
|
|
|
|
|
|
int my_mb_wc_8bit(CHARSET_INFO *cs,my_wc_t *wc,
|
|
const unsigned char *str,
|
|
const unsigned char *end __attribute__((unused)))
|
|
{
|
|
if (str >= end)
|
|
return MY_CS_TOOFEW(0);
|
|
|
|
*wc=cs->tab_to_uni[*str];
|
|
return (!wc[0] && str[0]) ? MY_CS_ILSEQ : 1;
|
|
}
|
|
|
|
int my_wc_mb_8bit(CHARSET_INFO *cs,my_wc_t wc,
|
|
unsigned char *str,
|
|
unsigned char *end __attribute__((unused)))
|
|
{
|
|
MY_UNI_IDX *idx;
|
|
|
|
if (str >= end)
|
|
return MY_CS_TOOSMALL;
|
|
|
|
for (idx=cs->tab_from_uni; idx->tab ; idx++)
|
|
{
|
|
if (idx->from <= wc && idx->to >= wc)
|
|
{
|
|
str[0]= idx->tab[wc - idx->from];
|
|
return (!str[0] && wc) ? MY_CS_ILUNI : 1;
|
|
}
|
|
}
|
|
return MY_CS_ILUNI;
|
|
}
|
|
|
|
|
|
/*
|
|
We can't use vsprintf here as it's not guaranteed to return
|
|
the length on all operating systems.
|
|
This function is also not called in a safe environment, so the
|
|
end buffer must be checked.
|
|
*/
|
|
|
|
int my_snprintf_8bit(CHARSET_INFO *cs __attribute__((unused)),
|
|
char* to, uint n __attribute__((unused)),
|
|
const char* fmt, ...)
|
|
{
|
|
va_list args;
|
|
int result;
|
|
va_start(args,fmt);
|
|
result= my_vsnprintf(to, n, fmt, args);
|
|
va_end(args);
|
|
return result;
|
|
}
|
|
|
|
|
|
void my_hash_sort_simple(CHARSET_INFO *cs,
|
|
const uchar *key, uint len,
|
|
ulong *nr1, ulong *nr2)
|
|
{
|
|
register uchar *sort_order=cs->sort_order;
|
|
const uchar *end= key + len;
|
|
|
|
/*
|
|
Remove end space. We have to do this to be able to compare
|
|
'A ' and 'A' as identical
|
|
*/
|
|
while (end > key && end[-1] == ' ')
|
|
end--;
|
|
|
|
for (; key < (uchar*) end ; key++)
|
|
{
|
|
nr1[0]^=(ulong) ((((uint) nr1[0] & 63)+nr2[0]) *
|
|
((uint) sort_order[(uint) *key])) + (nr1[0] << 8);
|
|
nr2[0]+=3;
|
|
}
|
|
}
|
|
|
|
|
|
long my_strntol_8bit(CHARSET_INFO *cs,
|
|
const char *nptr, uint l, int base,
|
|
char **endptr, int *err)
|
|
{
|
|
int negative;
|
|
register uint32 cutoff;
|
|
register unsigned int cutlim;
|
|
register uint32 i;
|
|
register const char *s;
|
|
register unsigned char c;
|
|
const char *save, *e;
|
|
int overflow;
|
|
|
|
*err= 0; /* Initialize error indicator */
|
|
#ifdef NOT_USED
|
|
if (base < 0 || base == 1 || base > 36)
|
|
base = 10;
|
|
#endif
|
|
|
|
s = nptr;
|
|
e = nptr+l;
|
|
|
|
for ( ; s<e && my_isspace(cs, *s) ; s++);
|
|
|
|
if (s == e)
|
|
{
|
|
goto noconv;
|
|
}
|
|
|
|
/* Check for a sign. */
|
|
if (*s == '-')
|
|
{
|
|
negative = 1;
|
|
++s;
|
|
}
|
|
else if (*s == '+')
|
|
{
|
|
negative = 0;
|
|
++s;
|
|
}
|
|
else
|
|
negative = 0;
|
|
|
|
#ifdef NOT_USED
|
|
if (base == 16 && s[0] == '0' && (s[1]=='X' || s[1]=='x'))
|
|
s += 2;
|
|
#endif
|
|
|
|
#ifdef NOT_USED
|
|
if (base == 0)
|
|
{
|
|
if (*s == '0')
|
|
{
|
|
if (s[1]=='X' || s[1]=='x')
|
|
{
|
|
s += 2;
|
|
base = 16;
|
|
}
|
|
else
|
|
base = 8;
|
|
}
|
|
else
|
|
base = 10;
|
|
}
|
|
#endif
|
|
|
|
save = s;
|
|
cutoff = ((uint32)~0L) / (uint32) base;
|
|
cutlim = (uint) (((uint32)~0L) % (uint32) base);
|
|
|
|
overflow = 0;
|
|
i = 0;
|
|
for (c = *s; s != e; c = *++s)
|
|
{
|
|
if (c>='0' && c<='9')
|
|
c -= '0';
|
|
else if (c>='A' && c<='Z')
|
|
c = c - 'A' + 10;
|
|
else if (c>='a' && c<='z')
|
|
c = c - 'a' + 10;
|
|
else
|
|
break;
|
|
if (c >= base)
|
|
break;
|
|
if (i > cutoff || (i == cutoff && c > cutlim))
|
|
overflow = 1;
|
|
else
|
|
{
|
|
i *= (uint32) base;
|
|
i += c;
|
|
}
|
|
}
|
|
|
|
if (s == save)
|
|
goto noconv;
|
|
|
|
if (endptr != NULL)
|
|
*endptr = (char *) s;
|
|
|
|
if (negative)
|
|
{
|
|
if (i > (uint32) INT_MIN32)
|
|
overflow = 1;
|
|
}
|
|
else if (i > INT_MAX32)
|
|
overflow = 1;
|
|
|
|
if (overflow)
|
|
{
|
|
err[0]= ERANGE;
|
|
return negative ? INT_MIN32 : INT_MAX32;
|
|
}
|
|
|
|
return (negative ? -((long) i) : (long) i);
|
|
|
|
noconv:
|
|
err[0]= EDOM;
|
|
if (endptr != NULL)
|
|
*endptr = (char *) nptr;
|
|
return 0L;
|
|
}
|
|
|
|
|
|
ulong my_strntoul_8bit(CHARSET_INFO *cs,
|
|
const char *nptr, uint l, int base,
|
|
char **endptr, int *err)
|
|
{
|
|
int negative;
|
|
register uint32 cutoff;
|
|
register unsigned int cutlim;
|
|
register uint32 i;
|
|
register const char *s;
|
|
register unsigned char c;
|
|
const char *save, *e;
|
|
int overflow;
|
|
|
|
*err= 0; /* Initialize error indicator */
|
|
#ifdef NOT_USED
|
|
if (base < 0 || base == 1 || base > 36)
|
|
base = 10;
|
|
#endif
|
|
|
|
s = nptr;
|
|
e = nptr+l;
|
|
|
|
for( ; s<e && my_isspace(cs, *s); s++);
|
|
|
|
if (s==e)
|
|
{
|
|
goto noconv;
|
|
}
|
|
|
|
if (*s == '-')
|
|
{
|
|
negative = 1;
|
|
++s;
|
|
}
|
|
else if (*s == '+')
|
|
{
|
|
negative = 0;
|
|
++s;
|
|
}
|
|
else
|
|
negative = 0;
|
|
|
|
#ifdef NOT_USED
|
|
if (base == 16 && s[0] == '0' && (s[1]=='X' || s[1]=='x'))
|
|
s += 2;
|
|
#endif
|
|
|
|
#ifdef NOT_USED
|
|
if (base == 0)
|
|
{
|
|
if (*s == '0')
|
|
{
|
|
if (s[1]=='X' || s[1]=='x')
|
|
{
|
|
s += 2;
|
|
base = 16;
|
|
}
|
|
else
|
|
base = 8;
|
|
}
|
|
else
|
|
base = 10;
|
|
}
|
|
#endif
|
|
|
|
save = s;
|
|
cutoff = ((uint32)~0L) / (uint32) base;
|
|
cutlim = (uint) (((uint32)~0L) % (uint32) base);
|
|
overflow = 0;
|
|
i = 0;
|
|
|
|
for (c = *s; s != e; c = *++s)
|
|
{
|
|
if (c>='0' && c<='9')
|
|
c -= '0';
|
|
else if (c>='A' && c<='Z')
|
|
c = c - 'A' + 10;
|
|
else if (c>='a' && c<='z')
|
|
c = c - 'a' + 10;
|
|
else
|
|
break;
|
|
if (c >= base)
|
|
break;
|
|
if (i > cutoff || (i == cutoff && c > cutlim))
|
|
overflow = 1;
|
|
else
|
|
{
|
|
i *= (uint32) base;
|
|
i += c;
|
|
}
|
|
}
|
|
|
|
if (s == save)
|
|
goto noconv;
|
|
|
|
if (endptr != NULL)
|
|
*endptr = (char *) s;
|
|
|
|
if (overflow)
|
|
{
|
|
err[0]= ERANGE;
|
|
return (~(uint32) 0);
|
|
}
|
|
|
|
return (negative ? -((long) i) : (long) i);
|
|
|
|
noconv:
|
|
err[0]= EDOM;
|
|
if (endptr != NULL)
|
|
*endptr = (char *) nptr;
|
|
return 0L;
|
|
}
|
|
|
|
|
|
longlong my_strntoll_8bit(CHARSET_INFO *cs __attribute__((unused)),
|
|
const char *nptr, uint l, int base,
|
|
char **endptr,int *err)
|
|
{
|
|
int negative;
|
|
register ulonglong cutoff;
|
|
register unsigned int cutlim;
|
|
register ulonglong i;
|
|
register const char *s, *e;
|
|
register unsigned char c;
|
|
const char *save;
|
|
int overflow;
|
|
|
|
*err= 0; /* Initialize error indicator */
|
|
#ifdef NOT_USED
|
|
if (base < 0 || base == 1 || base > 36)
|
|
base = 10;
|
|
#endif
|
|
|
|
s = nptr;
|
|
e = nptr+l;
|
|
|
|
for(; s<e && my_isspace(cs,*s); s++);
|
|
|
|
if (s == e)
|
|
{
|
|
goto noconv;
|
|
}
|
|
|
|
if (*s == '-')
|
|
{
|
|
negative = 1;
|
|
++s;
|
|
}
|
|
else if (*s == '+')
|
|
{
|
|
negative = 0;
|
|
++s;
|
|
}
|
|
else
|
|
negative = 0;
|
|
|
|
#ifdef NOT_USED
|
|
if (base == 16 && s[0] == '0' && (s[1]=='X'|| s[1]=='x'))
|
|
s += 2;
|
|
#endif
|
|
|
|
#ifdef NOT_USED
|
|
if (base == 0)
|
|
{
|
|
if (*s == '0')
|
|
{
|
|
if (s[1]=='X' || s[1]=='x')
|
|
{
|
|
s += 2;
|
|
base = 16;
|
|
}
|
|
else
|
|
base = 8;
|
|
}
|
|
else
|
|
base = 10;
|
|
}
|
|
#endif
|
|
|
|
save = s;
|
|
|
|
cutoff = (~(ulonglong) 0) / (unsigned long int) base;
|
|
cutlim = (uint) ((~(ulonglong) 0) % (unsigned long int) base);
|
|
|
|
overflow = 0;
|
|
i = 0;
|
|
for (c = *s; s != e; c = *++s)
|
|
{
|
|
if (c>='0' && c<='9')
|
|
c -= '0';
|
|
else if (c>='A' && c<='Z')
|
|
c = c - 'A' + 10;
|
|
else if (c>='a' && c<='z')
|
|
c = c - 'a' + 10;
|
|
else
|
|
break;
|
|
if (c >= base)
|
|
break;
|
|
if (i > cutoff || (i == cutoff && c > cutlim))
|
|
overflow = 1;
|
|
else
|
|
{
|
|
i *= (ulonglong) base;
|
|
i += c;
|
|
}
|
|
}
|
|
|
|
if (s == save)
|
|
goto noconv;
|
|
|
|
if (endptr != NULL)
|
|
*endptr = (char *) s;
|
|
|
|
if (negative)
|
|
{
|
|
if (i > (ulonglong) LONGLONG_MIN)
|
|
overflow = 1;
|
|
}
|
|
else if (i > (ulonglong) LONGLONG_MAX)
|
|
overflow = 1;
|
|
|
|
if (overflow)
|
|
{
|
|
err[0]= ERANGE;
|
|
return negative ? LONGLONG_MIN : LONGLONG_MAX;
|
|
}
|
|
|
|
return (negative ? -((longlong) i) : (longlong) i);
|
|
|
|
noconv:
|
|
err[0]= EDOM;
|
|
if (endptr != NULL)
|
|
*endptr = (char *) nptr;
|
|
return 0L;
|
|
}
|
|
|
|
|
|
ulonglong my_strntoull_8bit(CHARSET_INFO *cs,
|
|
const char *nptr, uint l, int base,
|
|
char **endptr, int *err)
|
|
{
|
|
int negative;
|
|
register ulonglong cutoff;
|
|
register unsigned int cutlim;
|
|
register ulonglong i;
|
|
register const char *s, *e;
|
|
register unsigned char c;
|
|
const char *save;
|
|
int overflow;
|
|
|
|
*err= 0; /* Initialize error indicator */
|
|
#ifdef NOT_USED
|
|
if (base < 0 || base == 1 || base > 36)
|
|
base = 10;
|
|
#endif
|
|
|
|
s = nptr;
|
|
e = nptr+l;
|
|
|
|
for(; s<e && my_isspace(cs,*s); s++);
|
|
|
|
if (s == e)
|
|
{
|
|
goto noconv;
|
|
}
|
|
|
|
if (*s == '-')
|
|
{
|
|
negative = 1;
|
|
++s;
|
|
}
|
|
else if (*s == '+')
|
|
{
|
|
negative = 0;
|
|
++s;
|
|
}
|
|
else
|
|
negative = 0;
|
|
|
|
#ifdef NOT_USED
|
|
if (base == 16 && s[0] == '0' && (s[1]=='X' || s[1]=='x'))
|
|
s += 2;
|
|
#endif
|
|
|
|
#ifdef NOT_USED
|
|
if (base == 0)
|
|
{
|
|
if (*s == '0')
|
|
{
|
|
if (s[1]=='X' || s[1]=='x')
|
|
{
|
|
s += 2;
|
|
base = 16;
|
|
}
|
|
else
|
|
base = 8;
|
|
}
|
|
else
|
|
base = 10;
|
|
}
|
|
#endif
|
|
|
|
save = s;
|
|
|
|
cutoff = (~(ulonglong) 0) / (unsigned long int) base;
|
|
cutlim = (uint) ((~(ulonglong) 0) % (unsigned long int) base);
|
|
|
|
overflow = 0;
|
|
i = 0;
|
|
for (c = *s; s != e; c = *++s)
|
|
{
|
|
if (c>='0' && c<='9')
|
|
c -= '0';
|
|
else if (c>='A' && c<='Z')
|
|
c = c - 'A' + 10;
|
|
else if (c>='a' && c<='z')
|
|
c = c - 'a' + 10;
|
|
else
|
|
break;
|
|
if (c >= base)
|
|
break;
|
|
if (i > cutoff || (i == cutoff && c > cutlim))
|
|
overflow = 1;
|
|
else
|
|
{
|
|
i *= (ulonglong) base;
|
|
i += c;
|
|
}
|
|
}
|
|
|
|
if (s == save)
|
|
goto noconv;
|
|
|
|
if (endptr != NULL)
|
|
*endptr = (char *) s;
|
|
|
|
if (overflow)
|
|
{
|
|
err[0]= ERANGE;
|
|
return (~(ulonglong) 0);
|
|
}
|
|
|
|
return (negative ? -((longlong) i) : (longlong) i);
|
|
|
|
noconv:
|
|
err[0]= EDOM;
|
|
if (endptr != NULL)
|
|
*endptr = (char *) nptr;
|
|
return 0L;
|
|
}
|
|
|
|
/*
|
|
Read double from string
|
|
|
|
SYNOPSIS:
|
|
my_strntod_8bit()
|
|
cs Character set information
|
|
str String to convert to double
|
|
length Optional length for string.
|
|
end result pointer to end of converted string
|
|
err Error number if failed conversion
|
|
|
|
NOTES:
|
|
If length is not INT_MAX32 or str[length] != 0 then the given str must
|
|
be writeable
|
|
If length == INT_MAX32 the str must be \0 terminated.
|
|
|
|
It's implemented this way to save a buffer allocation and a memory copy.
|
|
|
|
RETURN
|
|
Value of number in string
|
|
*/
|
|
|
|
|
|
double my_strntod_8bit(CHARSET_INFO *cs __attribute__((unused)),
|
|
char *str, uint length,
|
|
char **end, int *err)
|
|
{
|
|
char end_char;
|
|
double result;
|
|
|
|
errno= 0; /* Safety */
|
|
|
|
/*
|
|
The following define is to avoid warnings from valgrind as str[length]
|
|
may not be defined (which is not fatal in real life)
|
|
*/
|
|
|
|
#ifdef HAVE_purify
|
|
if (length == INT_MAX32)
|
|
#else
|
|
if (length == INT_MAX32 || str[length] == 0)
|
|
#endif
|
|
result= my_strtod(str, end);
|
|
else
|
|
{
|
|
end_char= str[length];
|
|
str[length]= 0;
|
|
result= my_strtod(str, end);
|
|
str[length]= end_char; /* Restore end char */
|
|
}
|
|
*err= errno;
|
|
return result;
|
|
}
|
|
|
|
|
|
/*
|
|
This is a fast version optimized for the case of radix 10 / -10
|
|
|
|
Assume len >= 1
|
|
*/
|
|
|
|
int my_long10_to_str_8bit(CHARSET_INFO *cs __attribute__((unused)),
|
|
char *dst, uint len, int radix, long int val)
|
|
{
|
|
char buffer[66];
|
|
register char *p, *e;
|
|
long int new_val;
|
|
uint sign=0;
|
|
|
|
e = p = &buffer[sizeof(buffer)-1];
|
|
*p= 0;
|
|
|
|
if (radix < 0)
|
|
{
|
|
if (val < 0)
|
|
{
|
|
val= -val;
|
|
*dst++= '-';
|
|
len--;
|
|
sign= 1;
|
|
}
|
|
}
|
|
|
|
new_val = (long) ((unsigned long int) val / 10);
|
|
*--p = '0'+ (char) ((unsigned long int) val - (unsigned long) new_val * 10);
|
|
val = new_val;
|
|
|
|
while (val != 0)
|
|
{
|
|
new_val=val/10;
|
|
*--p = '0' + (char) (val-new_val*10);
|
|
val= new_val;
|
|
}
|
|
|
|
len= min(len, (uint) (e-p));
|
|
memcpy(dst, p, len);
|
|
return (int) len+sign;
|
|
}
|
|
|
|
|
|
int my_longlong10_to_str_8bit(CHARSET_INFO *cs __attribute__((unused)),
|
|
char *dst, uint len, int radix, longlong val)
|
|
{
|
|
char buffer[65];
|
|
register char *p, *e;
|
|
long long_val;
|
|
uint sign= 0;
|
|
|
|
if (radix < 0)
|
|
{
|
|
if (val < 0)
|
|
{
|
|
val = -val;
|
|
*dst++= '-';
|
|
len--;
|
|
sign= 1;
|
|
}
|
|
}
|
|
|
|
e = p = &buffer[sizeof(buffer)-1];
|
|
*p= 0;
|
|
|
|
if (val == 0)
|
|
{
|
|
*--p= '0';
|
|
len= 1;
|
|
goto cnv;
|
|
}
|
|
|
|
while ((ulonglong) val > (ulonglong) LONG_MAX)
|
|
{
|
|
ulonglong quo=(ulonglong) val/(uint) 10;
|
|
uint rem= (uint) (val- quo* (uint) 10);
|
|
*--p = '0' + rem;
|
|
val= quo;
|
|
}
|
|
|
|
long_val= (long) val;
|
|
while (long_val != 0)
|
|
{
|
|
long quo= long_val/10;
|
|
*--p = '0' + (long_val - quo*10);
|
|
long_val= quo;
|
|
}
|
|
|
|
len= min(len, (uint) (e-p));
|
|
cnv:
|
|
memcpy(dst, p, len);
|
|
return len+sign;
|
|
}
|
|
|
|
|
|
/*
|
|
** Compare string against string with wildcard
|
|
** 0 if matched
|
|
** -1 if not matched with wildcard
|
|
** 1 if matched with wildcard
|
|
*/
|
|
|
|
#ifdef LIKE_CMP_TOUPPER
|
|
#define likeconv(s,A) (uchar) my_toupper(s,A)
|
|
#else
|
|
#define likeconv(s,A) (uchar) (s)->sort_order[(uchar) (A)]
|
|
#endif
|
|
|
|
#define INC_PTR(cs,A,B) (A)++
|
|
|
|
|
|
int my_wildcmp_8bit(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 || likeconv(cs,*wildstr++) != likeconv(cs,*str++))
|
|
return(1); /* No match */
|
|
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);
|
|
INC_PTR(cs,str,str_end);
|
|
} while (++wildstr < wildend && *wildstr == w_one);
|
|
if (wildstr == wildend)
|
|
break;
|
|
}
|
|
if (*wildstr == w_many)
|
|
{ /* Found w_many */
|
|
uchar 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);
|
|
INC_PTR(cs,str,str_end);
|
|
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;
|
|
|
|
INC_PTR(cs,wildstr,wildend); /* This is compared trough cmp */
|
|
cmp=likeconv(cs,cmp);
|
|
do
|
|
{
|
|
while (str != str_end && (uchar) likeconv(cs,*str) != cmp)
|
|
str++;
|
|
if (str++ == str_end) return(-1);
|
|
{
|
|
int tmp=my_wildcmp_8bit(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);
|
|
}
|
|
|
|
|
|
/*
|
|
** Calculate min_str and max_str that ranges a LIKE string.
|
|
** Arguments:
|
|
** ptr Pointer to LIKE string.
|
|
** ptr_length Length of LIKE string.
|
|
** escape Escape character in LIKE. (Normally '\').
|
|
** All escape characters should be removed from min_str and max_str
|
|
** res_length Length of min_str and max_str.
|
|
** min_str Smallest case sensitive string that ranges LIKE.
|
|
** Should be space padded to res_length.
|
|
** max_str Largest case sensitive string that ranges LIKE.
|
|
** Normally padded with the biggest character sort value.
|
|
**
|
|
** The function should return 0 if ok and 1 if the LIKE string can't be
|
|
** optimized !
|
|
*/
|
|
|
|
my_bool my_like_range_simple(CHARSET_INFO *cs,
|
|
const char *ptr,uint ptr_length,
|
|
pbool escape, pbool w_one, pbool w_many,
|
|
uint res_length,
|
|
char *min_str,char *max_str,
|
|
uint *min_length,uint *max_length)
|
|
{
|
|
const char *end=ptr+ptr_length;
|
|
char *min_org=min_str;
|
|
char *min_end=min_str+res_length;
|
|
|
|
for (; ptr != end && min_str != min_end ; ptr++)
|
|
{
|
|
if (*ptr == escape && ptr+1 != end)
|
|
{
|
|
ptr++; /* Skip escape */
|
|
*min_str++= *max_str++ = *ptr;
|
|
continue;
|
|
}
|
|
if (*ptr == w_one) /* '_' in SQL */
|
|
{
|
|
*min_str++='\0'; /* This should be min char */
|
|
*max_str++= (char) cs->max_sort_char;
|
|
continue;
|
|
}
|
|
if (*ptr == w_many) /* '%' in SQL */
|
|
{
|
|
/* Calculate length of keys */
|
|
*min_length= ((cs->state & MY_CS_BINSORT) ? (uint) (min_str - min_org) :
|
|
res_length);
|
|
*max_length= res_length;
|
|
do
|
|
{
|
|
*min_str++= 0;
|
|
*max_str++= (char) cs->max_sort_char;
|
|
} while (min_str != min_end);
|
|
return 0;
|
|
}
|
|
*min_str++= *max_str++ = *ptr;
|
|
}
|
|
|
|
*min_length= *max_length = (uint) (min_str - min_org);
|
|
while (min_str != min_end)
|
|
*min_str++= *max_str++ = ' '; /* Because if key compression */
|
|
return 0;
|
|
}
|
|
|
|
|
|
ulong my_scan_8bit(CHARSET_INFO *cs, const char *str, const char *end, int sq)
|
|
{
|
|
const char *str0= str;
|
|
switch (sq)
|
|
{
|
|
case MY_SEQ_INTTAIL:
|
|
if (*str == '.')
|
|
{
|
|
for(str++ ; str != end && *str == '0' ; str++);
|
|
return str-str0;
|
|
}
|
|
return 0;
|
|
|
|
case MY_SEQ_SPACES:
|
|
for ( ; str < end ; str++)
|
|
{
|
|
if (!my_isspace(cs,*str))
|
|
break;
|
|
}
|
|
return str-str0;
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
void my_fill_8bit(CHARSET_INFO *cs __attribute__((unused)),
|
|
char *s, uint l, int fill)
|
|
{
|
|
bfill(s,l,fill);
|
|
}
|
|
|
|
|
|
uint my_numchars_8bit(CHARSET_INFO *cs __attribute__((unused)),
|
|
const char *b, const char *e)
|
|
{
|
|
return e-b;
|
|
}
|
|
|
|
|
|
uint my_numcells_8bit(CHARSET_INFO *cs __attribute__((unused)),
|
|
const char *b, const char *e)
|
|
{
|
|
return e-b;
|
|
}
|
|
|
|
|
|
uint my_charpos_8bit(CHARSET_INFO *cs __attribute__((unused)),
|
|
const char *b __attribute__((unused)),
|
|
const char *e __attribute__((unused)),
|
|
uint pos)
|
|
{
|
|
return pos;
|
|
}
|
|
|
|
|
|
uint my_well_formed_len_8bit(CHARSET_INFO *cs __attribute__((unused)),
|
|
const char *start,
|
|
const char *end,
|
|
uint nchars)
|
|
{
|
|
uint nbytes= (uint) (end-start);
|
|
return min(nbytes, nchars);
|
|
}
|
|
|
|
|
|
uint my_lengthsp_8bit(CHARSET_INFO *cs __attribute__((unused)),
|
|
const char *ptr, uint length)
|
|
{
|
|
const char *end= ptr+length;
|
|
while (end > ptr && end[-1] == ' ')
|
|
end--;
|
|
return (uint) (end-ptr);
|
|
}
|
|
|
|
|
|
uint my_instr_simple(CHARSET_INFO *cs,
|
|
const char *b, uint b_length,
|
|
const char *s, uint s_length,
|
|
my_match_t *match, uint nmatch)
|
|
{
|
|
register const uchar *str, *search, *end, *search_end;
|
|
|
|
if (s_length <= b_length)
|
|
{
|
|
if (!s_length)
|
|
{
|
|
if (nmatch)
|
|
{
|
|
match->beg= 0;
|
|
match->end= 0;
|
|
match->mblen= 0;
|
|
}
|
|
return 1; /* Empty string is always found */
|
|
}
|
|
|
|
str= (const uchar*) b;
|
|
search= (const uchar*) s;
|
|
end= (const uchar*) b+b_length-s_length+1;
|
|
search_end= (const uchar*) s + s_length;
|
|
|
|
skip:
|
|
while (str != end)
|
|
{
|
|
if (cs->sort_order[*str++] == cs->sort_order[*search])
|
|
{
|
|
register const uchar *i,*j;
|
|
|
|
i= str;
|
|
j= search+1;
|
|
|
|
while (j != search_end)
|
|
if (cs->sort_order[*i++] != cs->sort_order[*j++])
|
|
goto skip;
|
|
|
|
if (nmatch > 0)
|
|
{
|
|
match[0].beg= 0;
|
|
match[0].end= str- (const uchar*)b-1;
|
|
match[0].mblen= match[0].end;
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
typedef struct
|
|
{
|
|
int nchars;
|
|
MY_UNI_IDX uidx;
|
|
} uni_idx;
|
|
|
|
#define PLANE_SIZE 0x100
|
|
#define PLANE_NUM 0x100
|
|
#define PLANE_NUMBER(x) (((x)>>8) % PLANE_NUM)
|
|
|
|
static int pcmp(const void * f, const void * s)
|
|
{
|
|
const uni_idx *F= (const uni_idx*) f;
|
|
const uni_idx *S= (const uni_idx*) s;
|
|
int res;
|
|
|
|
if (!(res=((S->nchars)-(F->nchars))))
|
|
res=((F->uidx.from)-(S->uidx.to));
|
|
return res;
|
|
}
|
|
|
|
static my_bool create_fromuni(CHARSET_INFO *cs, void *(*alloc)(uint))
|
|
{
|
|
uni_idx idx[PLANE_NUM];
|
|
int i,n;
|
|
|
|
/*
|
|
Check that Unicode map is loaded.
|
|
It can be not loaded when the collation is
|
|
listed in Index.xml but not specified
|
|
in the character set specific XML file.
|
|
*/
|
|
if (!cs->tab_to_uni)
|
|
return TRUE;
|
|
|
|
/* Clear plane statistics */
|
|
bzero(idx,sizeof(idx));
|
|
|
|
/* Count number of characters in each plane */
|
|
for (i=0; i< 0x100; i++)
|
|
{
|
|
uint16 wc=cs->tab_to_uni[i];
|
|
int pl= PLANE_NUMBER(wc);
|
|
|
|
if (wc || !i)
|
|
{
|
|
if (!idx[pl].nchars)
|
|
{
|
|
idx[pl].uidx.from=wc;
|
|
idx[pl].uidx.to=wc;
|
|
}else
|
|
{
|
|
idx[pl].uidx.from=wc<idx[pl].uidx.from?wc:idx[pl].uidx.from;
|
|
idx[pl].uidx.to=wc>idx[pl].uidx.to?wc:idx[pl].uidx.to;
|
|
}
|
|
idx[pl].nchars++;
|
|
}
|
|
}
|
|
|
|
/* Sort planes in descending order */
|
|
qsort(&idx,PLANE_NUM,sizeof(uni_idx),&pcmp);
|
|
|
|
for (i=0; i < PLANE_NUM; i++)
|
|
{
|
|
int ch,numchars;
|
|
|
|
/* Skip empty plane */
|
|
if (!idx[i].nchars)
|
|
break;
|
|
|
|
numchars=idx[i].uidx.to-idx[i].uidx.from+1;
|
|
if (!(idx[i].uidx.tab=(uchar*) alloc(numchars * sizeof(*idx[i].uidx.tab))))
|
|
return TRUE;
|
|
|
|
bzero(idx[i].uidx.tab,numchars*sizeof(*idx[i].uidx.tab));
|
|
|
|
for (ch=1; ch < PLANE_SIZE; ch++)
|
|
{
|
|
uint16 wc=cs->tab_to_uni[ch];
|
|
if (wc >= idx[i].uidx.from && wc <= idx[i].uidx.to && wc)
|
|
{
|
|
int ofs= wc - idx[i].uidx.from;
|
|
idx[i].uidx.tab[ofs]= ch;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Allocate and fill reverse table for each plane */
|
|
n=i;
|
|
if (!(cs->tab_from_uni= (MY_UNI_IDX*) alloc(sizeof(MY_UNI_IDX)*(n+1))))
|
|
return TRUE;
|
|
|
|
for (i=0; i< n; i++)
|
|
cs->tab_from_uni[i]= idx[i].uidx;
|
|
|
|
/* Set end-of-list marker */
|
|
bzero(&cs->tab_from_uni[i],sizeof(MY_UNI_IDX));
|
|
return FALSE;
|
|
}
|
|
|
|
static my_bool my_cset_init_8bit(CHARSET_INFO *cs, void *(*alloc)(uint))
|
|
{
|
|
return create_fromuni(cs, alloc);
|
|
}
|
|
|
|
static void set_max_sort_char(CHARSET_INFO *cs)
|
|
{
|
|
uchar max_char;
|
|
uint i;
|
|
|
|
if (!cs->sort_order)
|
|
return;
|
|
|
|
max_char=cs->sort_order[(uchar) cs->max_sort_char];
|
|
for (i= 0; i < 256; i++)
|
|
{
|
|
if ((uchar) cs->sort_order[i] > max_char)
|
|
{
|
|
max_char=(uchar) cs->sort_order[i];
|
|
cs->max_sort_char= i;
|
|
}
|
|
}
|
|
}
|
|
|
|
static my_bool my_coll_init_simple(CHARSET_INFO *cs,
|
|
void *(*alloc)(uint) __attribute__((unused)))
|
|
{
|
|
set_max_sort_char(cs);
|
|
return FALSE;
|
|
}
|
|
|
|
|
|
longlong my_strtoll10_8bit(CHARSET_INFO *cs __attribute__((unused)),
|
|
const char *nptr, char **endptr, int *error)
|
|
{
|
|
return my_strtoll10(nptr, endptr, error);
|
|
}
|
|
|
|
|
|
MY_CHARSET_HANDLER my_charset_8bit_handler=
|
|
{
|
|
my_cset_init_8bit,
|
|
NULL, /* ismbchar */
|
|
my_mbcharlen_8bit, /* mbcharlen */
|
|
my_numchars_8bit,
|
|
my_charpos_8bit,
|
|
my_well_formed_len_8bit,
|
|
my_lengthsp_8bit,
|
|
my_numcells_8bit,
|
|
my_mb_wc_8bit,
|
|
my_wc_mb_8bit,
|
|
my_caseup_str_8bit,
|
|
my_casedn_str_8bit,
|
|
my_caseup_8bit,
|
|
my_casedn_8bit,
|
|
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_strtoll10_8bit,
|
|
my_scan_8bit
|
|
};
|
|
|
|
MY_COLLATION_HANDLER my_collation_8bit_simple_ci_handler =
|
|
{
|
|
my_coll_init_simple, /* init */
|
|
my_strnncoll_simple,
|
|
my_strnncollsp_simple,
|
|
my_strnxfrm_simple,
|
|
my_like_range_simple,
|
|
my_wildcmp_8bit,
|
|
my_strcasecmp_8bit,
|
|
my_instr_simple,
|
|
my_hash_sort_simple
|
|
};
|