14
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
16
/* Some useful string utility functions used by the MySQL server */
19
#include <drizzled/typelib.h>
20
#include <drizzled/charset.h>
19
#include "drizzled/strfunc.h"
20
#include "drizzled/typelib.h"
21
#include "drizzled/charset_info.h"
22
#include "drizzled/global_charset_info.h"
28
Return bitmap for strings used in a set
33
str Strings of set-strings separated by ','
34
err_pos If error, set to point to start of wrong set string
35
err_len If error, set to the length of wrong set string
36
set_warning Set to 1 if some string in set couldn't be used
39
We delete all end space from str before comparison
42
bitmap of all sets found in x.
43
set_warning is set to 1 if there was any sets that couldn't be set
46
static const char field_separator=',';
48
uint64_t find_set(TYPELIB *lib, const char *str, uint32_t length,
49
const CHARSET_INFO * const cs,
50
char **err_pos, uint32_t *err_len, bool *set_warning)
52
const CHARSET_INFO * const strip= cs ? cs : &my_charset_utf8_general_ci;
53
const char *end= str + strip->cset->lengthsp(strip, str, length);
55
*err_pos= 0; // No error yet
58
const char *start= str;
61
const char *pos= start;
65
for (; pos != end && *pos != field_separator; pos++)
67
var_len= (uint32_t) (pos - start);
68
uint32_t find= cs ? find_type2(lib, start, var_len, cs) :
69
find_type(lib, start, var_len, (bool) 0);
72
*err_pos= (char*) start;
77
found|= ((int64_t) 1 << (find - 1));
25
88
Function to find a string in a TYPELIB
37
100
> 0 position in TYPELIB->type_names +1
40
uint32_t TYPELIB::find_type(const char *find, uint32_t length, bool part_match) const
103
uint32_t find_type(const TYPELIB *lib, const char *find, uint32_t length,
42
106
uint32_t found_count=0, found_pos=0;
43
const char* end= find + length;
46
for (uint32_t pos= 0 ; (j= type_names[pos++]) ; )
107
const char *end= find+length;
110
for (uint32_t pos=0 ; (j=lib->type_names[pos++]) ; )
48
for (i= find ; i != end && my_toupper(system_charset_info, *i) == my_toupper(system_charset_info, *j); i++, j++)
112
for (i=find ; i != end &&
113
my_toupper(system_charset_info,*i) ==
114
my_toupper(system_charset_info,*j) ; i++, j++) ;
59
return found_count == 1 && part_match ? found_pos : 0;
123
return(found_count == 1 && part_match ? found_pos : 0);
77
141
>0 Offset+1 in typelib for matched string
80
uint32_t TYPELIB::find_type2(const char *x, uint32_t length, const charset_info_st *cs) const
144
uint32_t find_type2(const TYPELIB *typelib, const char *x, uint32_t length,
145
const CHARSET_INFO * const cs)
85
for (int pos=0 ; (j= type_names[pos]) ; pos++)
155
for (pos=0 ; (j=typelib->type_names[pos]) ; pos++)
87
157
if (!my_strnncoll(cs, (const unsigned char*) x, length,
88
(const unsigned char*) j, type_lengths[pos]))
158
(const unsigned char*) j, typelib->type_lengths[pos]))
94
164
} /* namespace drizzled */