1
/* Copyright (C) 2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
/* Some useful string utility functions used by the MySQL server */
19
#include "drizzled/strfunc.h"
20
#include "drizzled/typelib.h"
21
#include "drizzled/charset_info.h"
22
#include "drizzled/global_charset_info.h"
25
Return bitmap for strings used in a set
30
str Strings of set-strings separated by ','
31
err_pos If error, set to point to start of wrong set string
32
err_len If error, set to the length of wrong set string
33
set_warning Set to 1 if some string in set couldn't be used
36
We delete all end space from str before comparison
39
bitmap of all sets found in x.
40
set_warning is set to 1 if there was any sets that couldn't be set
43
static const char field_separator=',';
45
uint64_t find_set(TYPELIB *lib, const char *str, uint32_t length,
46
const CHARSET_INFO * const cs,
47
char **err_pos, uint32_t *err_len, bool *set_warning)
49
const CHARSET_INFO * const strip= cs ? cs : &my_charset_utf8_general_ci;
50
const char *end= str + strip->cset->lengthsp(strip, str, length);
52
*err_pos= 0; // No error yet
55
const char *start= str;
58
const char *pos= start;
62
for (; pos != end && *pos != field_separator; pos++)
64
var_len= (uint32_t) (pos - start);
65
uint32_t find= cs ? find_type2(lib, start, var_len, cs) :
66
find_type(lib, start, var_len, (bool) 0);
69
*err_pos= (char*) start;
74
found|= ((int64_t) 1 << (find - 1));
85
Function to find a string in a TYPELIB
86
(Same format as mysys/typelib.c)
90
lib TYPELIB (struct of pointer to values + count)
92
length Length of string to find
93
part_match Allow part matching of value
97
> 0 position in TYPELIB->type_names +1
100
uint32_t find_type(const TYPELIB *lib, const char *find, uint32_t length,
103
uint32_t found_count=0, found_pos=0;
104
const char *end= find+length;
107
for (uint32_t pos=0 ; (j=lib->type_names[pos++]) ; )
109
for (i=find ; i != end &&
110
my_toupper(system_charset_info,*i) ==
111
my_toupper(system_charset_info,*j) ; i++, j++) ;
120
return(found_count == 1 && part_match ? found_pos : 0);
125
Find a string in a list of strings according to collation
129
lib TYPELIB (struct of pointer to values + count)
132
cs Character set + collation to use for comparison
138
>0 Offset+1 in typelib for matched string
141
uint32_t find_type2(const TYPELIB *typelib, const char *x, uint32_t length,
142
const CHARSET_INFO * const cs)
152
for (pos=0 ; (j=typelib->type_names[pos]) ; pos++)
154
if (!my_strnncoll(cs, (const unsigned char*) x, length,
155
(const unsigned char*) j, typelib->type_lengths[pos]))