22
22
#include <drizzled/internal/m_string.h>
23
#include <drizzled/charset_info.h>
23
#include <drizzled/charset.h>
24
#include <drizzled/memory/root.h>
24
25
#include <drizzled/typelib.h>
29
29
static const char field_separator=',';
31
int st_typelib::find_type_or_exit(const char *x, const char *option) const
31
int TYPELIB::find_type_or_exit(const char *x, const char *option) const
33
int res= find_type(const_cast<char*>(x), 2);
33
int res= find_type(x, e_dont_complete);
55
55
lib TYPELIB (struct of pointer to values + count)
56
56
full_name bitmap of what to do
57
If & 1 accept only whole names
58
If & 2 don't expand if half field
59
If & 4 allow #number# as type
60
If & 8 use ',' as string terminator
57
If & 1 accept only whole names - e_match_full
58
If & 2 don't expand if half field - e_dont_complete
59
If & 4 allow #number# as type - e_allow_int
60
If & 8 use ',' as string terminator - e_use_comma
63
63
If part, uniq field is found and full_name == 0 then x is expanded
73
int st_typelib::find_type(const char *x, uint32_t full_name) const
75
assert(full_name & 2);
76
return find_type(const_cast<char*>(x), full_name);
79
int st_typelib::find_type(char *x, uint32_t full_name) const
73
int TYPELIB::find_type(const char *x, e_find_options full_name) const
75
assert(full_name & e_dont_complete);
86
81
for (int pos= 0; (j= type_names[pos]); pos++)
90
*i && (!(full_name & 8) || *i != field_separator) &&
91
my_toupper(&my_charset_utf8_general_ci,*i) ==
92
my_toupper(&my_charset_utf8_general_ci,*j) ; i++, j++) ;
84
for (; *i && *i != field_separator &&
85
my_charset_utf8_general_ci.toupper(*i) == my_charset_utf8_general_ci.toupper(*j); i++, j++)
96
i++; /* skip_end_space */
97
if (! *i || ((full_name & 8) && *i == field_separator))
91
i++; /* skip_end_space */
100
if ((!*i && (!(full_name & 8) || *i != field_separator)) &&
101
(!*j || !(full_name & 1)))
95
if (not *i && *i != field_separator && (not *j || not (full_name & e_match_full)))
107
if (find == 0 && (full_name & 4) && x[0] == '#' && strchr(x, '\0')[-1] == '#' &&
108
(findpos=atoi(x+1)-1) >= 0 && (uint32_t) findpos < count)
110
else if (find == 0 || ! x[0])
114
else if (find != 1 || (full_name & 1))
118
if (!(full_name & 2))
119
strcpy(x, type_names[findpos]);
101
if (find == 0 || not x[0])
103
if (find != 1 || (full_name & e_match_full))
120
105
return findpos + 1;
121
106
} /* find_type */
124
/* Get name of type nr 'nr' */
125
/* Warning first type is 1, 0 = empty field */
127
void st_typelib::make_type(char *to, uint32_t nr) const
132
strcpy(to, get_type(nr - 1));
137
/* Warning first type is 0 */
139
const char *st_typelib::get_type(uint32_t nr) const
141
if (nr < count && type_names)
142
return type_names[nr];
148
Create an integer value to represent the supplied comma-seperated
149
string where each string in the TYPELIB denotes a bit position.
153
x string to decompose
154
lib TYPELIB (struct of pointer to values + count)
155
err index (not char position) of string element which was not
156
found or 0 if there was no error
159
a integer representation of the supplied string
162
uint64_t st_typelib::find_typeset(const char *x, int *err) const
172
while (*x && *x != field_separator) x++;
173
int find= find_type(i, 2 | 8) - 1;
176
result|= (1ULL << find);
184
109
Create a copy of a specified TYPELIB structure.
196
TYPELIB *st_typelib::copy_typelib(memory::Root *root) const
121
TYPELIB *TYPELIB::copy_typelib(memory::Root& root) const
204
if (!(to= (TYPELIB*) root->alloc_root(sizeof(TYPELIB))))
207
if (!(to->type_names= (const char **)
208
root->alloc_root((sizeof(char *) + sizeof(int)) * (count + 1))))
209
return NULL; // leaking
210
to->type_lengths= (unsigned int *)(to->type_names + count + 1);
123
TYPELIB* to= new (root) TYPELIB;
124
to->type_names= (const char**)root.alloc((sizeof(char *) + sizeof(int)) * (count + 1));
125
to->type_lengths= (unsigned int*)(to->type_names + count + 1);
211
126
to->count= count;
214
if (!(to->name= root->strdup_root(name)))
215
return NULL; // leaking
220
for (i= 0; i < count; i++)
222
if (!(to->type_names[i]= root->strmake_root(type_names[i], type_lengths[i])))
223
return NULL; // leaking
127
to->name= name ? root.strdup(name) : NULL;
128
for (uint32_t i= 0; i < count; i++)
130
to->type_names[i]= root.strdup(type_names[i], type_lengths[i]);
224
131
to->type_lengths[i]= type_lengths[i];
226
133
to->type_names[to->count]= NULL;
227
134
to->type_lengths[to->count]= 0;