mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
New ctype functions/macros to support many charsets at a time
client/mysql.cc: new ctypes client/mysqldump.c: new ctypes client/mysqltest.c: new ctypes client/sql_string.cc: new ctypes client/sql_string.h: new ctypes extra/mysql_install.c: new ctypes extra/replace.c: new ctypes extra/resolve_stack_dump.c: new ctypes extra/resolveip.c: new ctypes heap/hp_hash.c: new ctypes include/m_ctype.h: new ctypes include/my_sys.h: new ctypes isam/_key.c: new ctypes isam/_search.c: new ctypes libmysql/Makefile.shared: new ctypes libmysql/libmysql.c: new ctypes myisam/ft_dump.c: new ctypes myisam/ft_parser.c: new ctypes myisam/mi_test1.c: new ctypes mysys/charset.c: new ctypes mysys/default.c: new ctypes mysys/getvar.c: new ctypes mysys/hash.c: new ctypes mysys/mf_casecnv.c: new ctypes mysys/mf_dirname.c: new ctypes mysys/mf_format.c: new ctypes mysys/mf_iocache2.c: new ctypes mysys/mf_soundex.c: new ctypes mysys/mf_wfile.c: new ctypes mysys/my_error.c: new ctypes mysys/my_getwd.c: new ctypes mysys/my_init.c: new ctypes mysys/my_vsnprintf.c: new ctypes mysys/typelib.c: new ctypes sql/convert.cc: new ctypes sql/des_key_file.cc: new ctypes sql/field.cc: new ctypes sql/field.h: new ctypes sql/field_conv.cc: new ctypes sql/filesort.cc: new ctypes sql/ha_innodb.cc: new ctypes sql/hostname.cc: new ctypes sql/init.cc: new ctypes sql/item.cc: new ctypes sql/item_func.cc: new ctypes sql/item_strfunc.cc: new ctypes sql/item_sum.cc: new ctypes sql/item_timefunc.cc: new ctypes sql/key.cc: new ctypes sql/log.cc: new ctypes sql/mysql_priv.h: new ctypes sql/mysqld.cc: new ctypes sql/opt_range.cc: new ctypes sql/procedure.cc: new ctypes sql/slave.cc: new ctypes sql/sql_acl.cc: new ctypes sql/sql_analyse.cc: new ctypes sql/sql_base.cc: new ctypes sql/sql_cache.cc: new ctypes sql/sql_db.cc: new ctypes sql/sql_handler.cc: new ctypes sql/sql_lex.cc: new ctypes sql/sql_parse.cc: new ctypes sql/sql_show.cc: new ctypes sql/sql_string.cc: new ctypes sql/sql_string.h: new ctypes sql/sql_table.cc: new ctypes sql/sql_yacc.yy: new ctypes sql/table.cc: new ctypes sql/time.cc: new ctypes strings/Makefile.am: new ctypes strings/ctype-big5.c: new ctypes strings/ctype-czech.c: new ctypes strings/ctype-gbk.c: new ctypes strings/ctype-latin1_de.c: new ctypes strings/ctype-sjis.c: new ctypes strings/ctype-tis620.c: new ctypes strings/ctype.c: new ctypes strings/str2int.c: new ctypes strings/strto.c: new ctypes tools/mysqlmanager.c: new ctypes
This commit is contained in:
@ -234,7 +234,7 @@ bool String::fill(uint32 max_length,char fill_char)
|
||||
|
||||
void String::strip_sp()
|
||||
{
|
||||
while (str_length && isspace(Ptr[str_length-1]))
|
||||
while (str_length && my_isspace(str_charset,Ptr[str_length-1]))
|
||||
str_length--;
|
||||
}
|
||||
|
||||
@ -296,10 +296,10 @@ uint32 String::numchars()
|
||||
register uint32 n=0,mblen;
|
||||
register const char *mbstr=Ptr;
|
||||
register const char *end=mbstr+str_length;
|
||||
if (use_mb(default_charset_info))
|
||||
if (use_mb(str_charset))
|
||||
{
|
||||
while (mbstr < end) {
|
||||
if ((mblen=my_ismbchar(default_charset_info, mbstr,end))) mbstr+=mblen;
|
||||
if ((mblen=my_ismbchar(str_charset, mbstr,end))) mbstr+=mblen;
|
||||
else ++mbstr;
|
||||
++n;
|
||||
}
|
||||
@ -316,11 +316,11 @@ int String::charpos(int i,uint32 offset)
|
||||
register uint32 mblen;
|
||||
register const char *mbstr=Ptr+offset;
|
||||
register const char *end=Ptr+str_length;
|
||||
if (use_mb(default_charset_info))
|
||||
if (use_mb(str_charset))
|
||||
{
|
||||
if (i<=0) return i;
|
||||
while (i && mbstr < end) {
|
||||
if ((mblen=my_ismbchar(default_charset_info, mbstr,end))) mbstr+=mblen;
|
||||
if ((mblen=my_ismbchar(str_charset, mbstr,end))) mbstr+=mblen;
|
||||
else ++mbstr;
|
||||
--i;
|
||||
}
|
||||
@ -361,6 +361,39 @@ skipp:
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
Search after a string without regarding to case
|
||||
This needs to be replaced when we have character sets per string
|
||||
*/
|
||||
|
||||
int String::strstr_case(const String &s,uint32 offset)
|
||||
{
|
||||
if (s.length()+offset <= str_length)
|
||||
{
|
||||
if (!s.length())
|
||||
return ((int) offset); // Empty string is always found
|
||||
|
||||
register const char *str = Ptr+offset;
|
||||
register const char *search=s.ptr();
|
||||
const char *end=Ptr+str_length-s.length()+1;
|
||||
const char *search_end=s.ptr()+s.length();
|
||||
skipp:
|
||||
while (str != end)
|
||||
{
|
||||
if (str_charset->sort_order[*str++] == str_charset->sort_order[*search])
|
||||
{
|
||||
register char *i,*j;
|
||||
i=(char*) str; j=(char*) search+1;
|
||||
while (j != search_end)
|
||||
if (str_charset->sort_order[*i++] !=
|
||||
str_charset->sort_order[*j++])
|
||||
goto skipp;
|
||||
return (int) (str-Ptr) -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
** Search string from end. Offset is offset to the end of string
|
||||
@ -428,6 +461,44 @@ bool String::replace(uint32 offset,uint32 arg_length,const String &to)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// added by Holyfoot for "geometry" needs
|
||||
int String::reserve(uint32 space_needed, uint32 grow_by)
|
||||
{
|
||||
if (Alloced_length < str_length + space_needed)
|
||||
{
|
||||
if (realloc(Alloced_length + max(space_needed, grow_by) - 1))
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void String::qs_append(const char *str)
|
||||
{
|
||||
int len = strlen(str);
|
||||
memcpy(Ptr + str_length, str, len + 1);
|
||||
str_length += len;
|
||||
}
|
||||
|
||||
void String::qs_append(double d)
|
||||
{
|
||||
char *buff = Ptr + str_length;
|
||||
sprintf(buff,"%.14g", d);
|
||||
str_length += strlen(buff);
|
||||
}
|
||||
|
||||
void String::qs_append(double *d)
|
||||
{
|
||||
double ld;
|
||||
float8get(ld, d);
|
||||
qs_append(ld);
|
||||
}
|
||||
|
||||
void String::qs_append(const char &c)
|
||||
{
|
||||
Ptr[str_length] = c;
|
||||
str_length += sizeof(c);
|
||||
}
|
||||
|
||||
|
||||
int sortcmp(const String *x,const String *y)
|
||||
{
|
||||
@ -436,15 +507,15 @@ int sortcmp(const String *x,const String *y)
|
||||
uint32 x_len=x->length(),y_len=y->length(),len=min(x_len,y_len);
|
||||
|
||||
#ifdef USE_STRCOLL
|
||||
if (use_strcoll(default_charset_info))
|
||||
if (use_strcoll(x->str_charset))
|
||||
{
|
||||
#ifndef CMP_ENDSPACE
|
||||
while (x_len && isspace(s[x_len-1]))
|
||||
while (x_len && my_isspace(x->str_charset,s[x_len-1]))
|
||||
x_len--;
|
||||
while (y_len && isspace(t[y_len-1]))
|
||||
while (y_len && my_isspace(x->str_charset,t[y_len-1]))
|
||||
y_len--;
|
||||
#endif
|
||||
return my_strnncoll(default_charset_info,
|
||||
return my_strnncoll(x->str_charset,
|
||||
(unsigned char *)s,x_len,(unsigned char *)t,y_len);
|
||||
}
|
||||
else
|
||||
@ -454,9 +525,10 @@ int sortcmp(const String *x,const String *y)
|
||||
y_len-=len;
|
||||
while (len--)
|
||||
{
|
||||
if (my_sort_order[(uchar) *s++] != my_sort_order[(uchar) *t++])
|
||||
return ((int) my_sort_order[(uchar) s[-1]] -
|
||||
(int) my_sort_order[(uchar) t[-1]]);
|
||||
if (x->str_charset->sort_order[(uchar) *s++] !=
|
||||
x->str_charset->sort_order[(uchar) *t++])
|
||||
return ((int) x->str_charset->sort_order[(uchar) s[-1]] -
|
||||
(int) x->str_charset->sort_order[(uchar) t[-1]]);
|
||||
}
|
||||
#ifndef CMP_ENDSPACE
|
||||
/* Don't compare end space in strings */
|
||||
@ -465,14 +537,14 @@ int sortcmp(const String *x,const String *y)
|
||||
{
|
||||
const char *end=t+y_len;
|
||||
for (; t != end ; t++)
|
||||
if (!isspace(*t))
|
||||
if (!my_isspace(x->str_charset,*t))
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
const char *end=s+x_len;
|
||||
for (; s != end ; s++)
|
||||
if (!isspace(*s))
|
||||
if (!my_isspace(x->str_charset,*s))
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@ -520,11 +592,10 @@ String *copy_if_not_alloced(String *to,String *from,uint32 from_length)
|
||||
/* Make it easier to handle different charactersets */
|
||||
|
||||
#ifdef USE_MB
|
||||
#define INC_PTR(A,B) A+=((use_mb_flag && \
|
||||
my_ismbchar(default_charset_info,A,B)) ? \
|
||||
my_ismbchar(default_charset_info,A,B) : 1)
|
||||
#define INC_PTR(cs,A,B) A+=((use_mb_flag && \
|
||||
my_ismbchar(cs,A,B)) ? my_ismbchar(cs,A,B) : 1)
|
||||
#else
|
||||
#define INC_PTR(A,B) A++
|
||||
#define INC_PTR(cs,A,B) A++
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -535,14 +606,14 @@ String *copy_if_not_alloced(String *to,String *from,uint32 from_length)
|
||||
*/
|
||||
|
||||
#ifdef LIKE_CMP_TOUPPER
|
||||
#define likeconv(A) (uchar) toupper(A)
|
||||
#define likeconv(s,A) (uchar) my_toupper(s,A)
|
||||
#else
|
||||
#define likeconv(A) (uchar) my_sort_order[(uchar) (A)]
|
||||
#define likeconv(s,A) (uchar) (s)->sort_order[(uchar) (A)]
|
||||
#endif
|
||||
|
||||
static int wild_case_compare(const char *str,const char *str_end,
|
||||
const char *wildstr,const char *wildend,
|
||||
char escape)
|
||||
int wild_case_compare(CHARSET_INFO *cs, const char *str,const char *str_end,
|
||||
const char *wildstr,const char *wildend,
|
||||
char escape)
|
||||
{
|
||||
int result= -1; // Not found, using wildcards
|
||||
#ifdef USE_MB
|
||||
@ -557,7 +628,7 @@ static int wild_case_compare(const char *str,const char *str_end,
|
||||
#ifdef USE_MB
|
||||
int l;
|
||||
if (use_mb_flag &&
|
||||
(l = my_ismbchar(default_charset_info, wildstr, wildend)))
|
||||
(l = my_ismbchar(cs, wildstr, wildend)))
|
||||
{
|
||||
if (str+l > str_end || memcmp(str, wildstr, l) != 0)
|
||||
return 1;
|
||||
@ -566,7 +637,7 @@ static int wild_case_compare(const char *str,const char *str_end,
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (str == str_end || likeconv(*wildstr++) != likeconv(*str++))
|
||||
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
|
||||
@ -576,9 +647,9 @@ static int wild_case_compare(const char *str,const char *str_end,
|
||||
{
|
||||
do
|
||||
{
|
||||
if (str == str_end) // Skipp one char if possible
|
||||
if (str == str_end) // Skip one char if possible
|
||||
return (result);
|
||||
INC_PTR(str,str_end);
|
||||
INC_PTR(cs,str,str_end);
|
||||
} while (++wildstr < wildend && *wildstr == wild_one);
|
||||
if (wildstr == wildend)
|
||||
break;
|
||||
@ -595,7 +666,7 @@ static int wild_case_compare(const char *str,const char *str_end,
|
||||
{
|
||||
if (str == str_end)
|
||||
return (-1);
|
||||
INC_PTR(str,str_end);
|
||||
INC_PTR(cs,str,str_end);
|
||||
continue;
|
||||
}
|
||||
break; // Not a wild character
|
||||
@ -613,10 +684,10 @@ static int wild_case_compare(const char *str,const char *str_end,
|
||||
int mblen;
|
||||
LINT_INIT(mblen);
|
||||
if (use_mb_flag)
|
||||
mblen = my_ismbchar(default_charset_info, wildstr, wildend);
|
||||
mblen = my_ismbchar(cs, wildstr, wildend);
|
||||
#endif
|
||||
INC_PTR(wildstr,wildend); // This is compared trough cmp
|
||||
cmp=likeconv(cmp);
|
||||
INC_PTR(cs,wildstr,wildend); // This is compared trough cmp
|
||||
cmp=likeconv(cs,cmp);
|
||||
do
|
||||
{
|
||||
#ifdef USE_MB
|
||||
@ -634,26 +705,26 @@ static int wild_case_compare(const char *str,const char *str_end,
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (!my_ismbchar(default_charset_info, str, str_end) &&
|
||||
likeconv(*str) == cmp)
|
||||
else if (!my_ismbchar(cs, str, str_end) &&
|
||||
likeconv(cs,*str) == cmp)
|
||||
{
|
||||
str++;
|
||||
break;
|
||||
}
|
||||
INC_PTR(str, str_end);
|
||||
INC_PTR(cs,str, str_end);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif /* USE_MB */
|
||||
while (str != str_end && likeconv(*str) != cmp)
|
||||
while (str != str_end && likeconv(cs,*str) != cmp)
|
||||
str++;
|
||||
if (str++ == str_end) return (-1);
|
||||
#ifdef USE_MB
|
||||
}
|
||||
#endif
|
||||
{
|
||||
int tmp=wild_case_compare(str,str_end,wildstr,wildend,escape);
|
||||
int tmp=wild_case_compare(cs,str,str_end,wildstr,wildend,escape);
|
||||
if (tmp <= 0)
|
||||
return (tmp);
|
||||
}
|
||||
@ -667,17 +738,23 @@ static int wild_case_compare(const char *str,const char *str_end,
|
||||
|
||||
int wild_case_compare(String &match,String &wild, char escape)
|
||||
{
|
||||
return wild_case_compare(match.ptr(),match.ptr()+match.length(),
|
||||
wild.ptr(), wild.ptr()+wild.length(),escape);
|
||||
DBUG_ENTER("wild_case_compare");
|
||||
DBUG_PRINT("enter",("match='%s', wild='%s', escape='%c'"
|
||||
,match.ptr(),wild.ptr(),escape));
|
||||
DBUG_RETURN(wild_case_compare(match.str_charset,match.ptr(),match.ptr()+match.length(),
|
||||
wild.ptr(), wild.ptr()+wild.length(),escape));
|
||||
}
|
||||
|
||||
/*
|
||||
** The following is used when using LIKE on binary strings
|
||||
*/
|
||||
|
||||
static int wild_compare(const char *str,const char *str_end,
|
||||
const char *wildstr,const char *wildend,char escape)
|
||||
int wild_compare(const char *str,const char *str_end,
|
||||
const char *wildstr,const char *wildend,char escape)
|
||||
{
|
||||
DBUG_ENTER("wild_compare");
|
||||
DBUG_PRINT("enter",("str='%s', str_end='%s', wildstr='%s', wildend='%s', escape='%c'"
|
||||
,str,str_end,wildstr,wildend,escape));
|
||||
int result= -1; // Not found, using wildcards
|
||||
while (wildstr != wildend)
|
||||
{
|
||||
@ -686,17 +763,21 @@ static int wild_compare(const char *str,const char *str_end,
|
||||
if (*wildstr == escape && wildstr+1 != wildend)
|
||||
wildstr++;
|
||||
if (str == str_end || *wildstr++ != *str++)
|
||||
return(1);
|
||||
{
|
||||
DBUG_RETURN(1);
|
||||
}
|
||||
if (wildstr == wildend)
|
||||
return (str != str_end); // Match if both are at end
|
||||
{
|
||||
DBUG_RETURN(str != str_end); // Match if both are at end
|
||||
}
|
||||
result=1; // Found an anchor char
|
||||
}
|
||||
if (*wildstr == wild_one)
|
||||
{
|
||||
do
|
||||
{
|
||||
if (str == str_end) // Skipp one char if possible
|
||||
return (result);
|
||||
if (str == str_end) // Skip one char if possible
|
||||
DBUG_RETURN(result);
|
||||
str++;
|
||||
} while (*++wildstr == wild_one && wildstr != wildend);
|
||||
if (wildstr == wildend)
|
||||
@ -713,17 +794,22 @@ static int wild_compare(const char *str,const char *str_end,
|
||||
if (*wildstr == wild_one)
|
||||
{
|
||||
if (str == str_end)
|
||||
return (-1);
|
||||
{
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
str++;
|
||||
continue;
|
||||
}
|
||||
break; // Not a wild character
|
||||
}
|
||||
if (wildstr == wildend)
|
||||
return(0); // Ok if wild_many is last
|
||||
{
|
||||
DBUG_RETURN(0); // Ok if wild_many is last
|
||||
}
|
||||
if (str == str_end)
|
||||
return -1;
|
||||
|
||||
{
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
char cmp;
|
||||
if ((cmp= *wildstr) == escape && wildstr+1 != wildend)
|
||||
cmp= *++wildstr;
|
||||
@ -732,22 +818,32 @@ static int wild_compare(const char *str,const char *str_end,
|
||||
{
|
||||
while (str != str_end && *str != cmp)
|
||||
str++;
|
||||
if (str++ == str_end) return (-1);
|
||||
if (str++ == str_end)
|
||||
{
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
{
|
||||
int tmp=wild_compare(str,str_end,wildstr,wildend,escape);
|
||||
if (tmp <= 0)
|
||||
return (tmp);
|
||||
{
|
||||
DBUG_RETURN(tmp);
|
||||
}
|
||||
}
|
||||
} while (str != str_end && wildstr[0] != wild_many);
|
||||
return(-1);
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
}
|
||||
return (str != str_end ? 1 : 0);
|
||||
DBUG_RETURN(str != str_end ? 1 : 0);
|
||||
}
|
||||
|
||||
|
||||
int wild_compare(String &match,String &wild, char escape)
|
||||
{
|
||||
return wild_compare(match.ptr(),match.ptr()+match.length(),
|
||||
wild.ptr(), wild.ptr()+wild.length(),escape);
|
||||
DBUG_ENTER("wild_compare");
|
||||
DBUG_PRINT("enter",("match='%s', wild='%s', escape='%c'"
|
||||
,match.ptr(),wild.ptr(),escape));
|
||||
DBUG_RETURN(wild_compare(match.ptr(),match.ptr()+match.length(),
|
||||
wild.ptr(), wild.ptr()+wild.length(),escape));
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user