38
38
static const char field_separator=',';
40
uint64_t find_set(TYPELIB *lib, const char *str, uint length,
40
uint64_t find_set(TYPELIB *lib, const char *str, uint32_t length,
41
41
const CHARSET_INFO * const cs,
42
char **err_pos, uint *err_len, bool *set_warning)
42
char **err_pos, uint32_t *err_len, bool *set_warning)
44
const CHARSET_INFO * const strip= cs ? cs : &my_charset_latin1;
44
const CHARSET_INFO * const strip= cs ? cs : &my_charset_utf8_general_ci;
45
45
const char *end= str + strip->cset->lengthsp(strip, str, length);
47
47
*err_pos= 0; // No error yet
50
const char *start= str;
50
const char *start= str;
53
53
const char *pos= start;
57
if (cs && cs->mbminlen > 1)
59
for ( ; pos < end; pos+= mblen)
62
if ((mblen= cs->cset->mb_wc(cs, &wc, (const uchar *) pos,
63
(const uchar *) end)) < 1)
64
mblen= 1; // Not to hang on a wrong multibyte sequence
65
if (wc == (my_wc_t) field_separator)
70
for (; pos != end && *pos != field_separator; pos++) ;
71
var_len= (uint) (pos - start);
72
uint find= cs ? find_type2(lib, start, var_len, cs) :
57
for (; pos != end && *pos != field_separator; pos++)
59
var_len= (uint32_t) (pos - start);
60
uint32_t find= cs ? find_type2(lib, start, var_len, cs) :
73
61
find_type(lib, start, var_len, (bool) 0);
104
92
> 0 position in TYPELIB->type_names +1
107
uint find_type(const TYPELIB *lib, const char *find, uint length,
95
uint32_t find_type(const TYPELIB *lib, const char *find, uint32_t length,
110
uint found_count=0, found_pos=0;
98
uint32_t found_count=0, found_pos=0;
111
99
const char *end= find+length;
114
for (uint pos=0 ; (j=lib->type_names[pos++]) ; )
102
for (uint32_t pos=0 ; (j=lib->type_names[pos++]) ; )
116
for (i=find ; i != end &&
117
my_toupper(system_charset_info,*i) ==
104
for (i=find ; i != end &&
105
my_toupper(system_charset_info,*i) ==
118
106
my_toupper(system_charset_info,*j) ; i++, j++) ;
159
147
for (pos=0 ; (j=typelib->type_names[pos]) ; pos++)
161
if (!my_strnncoll(cs, (const uchar*) x, length,
162
(const uchar*) j, typelib->type_lengths[pos]))
149
if (!my_strnncoll(cs, (const unsigned char*) x, length,
150
(const unsigned char*) j, typelib->type_lengths[pos]))
166
154
} /* find_type */
170
Un-hex all elements in a typelib
174
interval TYPELIB (struct of pointer to values + lengths + count)
182
void unhex_type2(TYPELIB *interval)
184
for (uint pos= 0; pos < interval->count; pos++)
187
for (from= to= (char*) interval->type_names[pos]; *from; )
190
Note, hexchar_to_int(*from++) doesn't work
191
one some compilers, e.g. IRIX. Looks like a compiler
192
bug in inline functions in combination with arguments
193
that have a side effect. So, let's use from[0] and from[1]
194
and increment 'from' by two later.
197
*to++= (char) (hexchar_to_int(from[0]) << 4) +
198
hexchar_to_int(from[1]);
201
interval->type_lengths[pos] /= 2;
207
Check if the first word in a string is one of the ones in TYPELIB
214
end_of_word Store value of last used byte here if we found word
218
> 1 lib->type_names[#-1] matched
219
end_of_word will point to separator character/end in 'val'
222
uint check_word(TYPELIB *lib, const char *val, const char *end,
223
const char **end_of_word)
228
/* Fiend end of word */
229
for (ptr= val ; ptr < end && my_isalpha(&my_charset_latin1, *ptr) ; ptr++)
231
if ((res=find_type(lib, val, (uint) (ptr - val), 1)) > 0)
238
Converts a string between character sets
242
from_cs source character set
243
from source, a null terminated string
244
to destination buffer
245
to_length destination buffer length
248
'to' is always terminated with a '\0' character.
249
If there is no enough space to convert whole string,
250
only prefix is converted, and terminated with '\0'.
257
uint strconvert(const CHARSET_INFO * const from_cs, const char *from,
258
const CHARSET_INFO * const to_cs, char *to, uint to_length, uint *errors)
263
uchar *to_end= (uchar*) to + to_length - 1;
264
my_charset_conv_mb_wc mb_wc= from_cs->cset->mb_wc;
265
my_charset_conv_wc_mb wc_mb= to_cs->cset->wc_mb;
271
Using 'from + 10' is safe:
272
- it is enough to scan a single character in any character set.
273
- if remaining string is shorter than 10, then mb_wc will return
274
with error because of unexpected '\0' character.
276
if ((cnvres= (*mb_wc)(from_cs, &wc,
277
(uchar*) from, (uchar*) from + 10)) > 0)
283
else if (cnvres == MY_CS_ILSEQ)
290
break; // Impossible char.
294
if ((cnvres= (*wc_mb)(to_cs, wc, (uchar*) to, to_end)) > 0)
296
else if (cnvres == MY_CS_ILUNI && wc != '?')
306
*errors= error_count;
307
return (uint32_t) (to - to_start);
313
Searches for a LEX_STRING in an LEX_STRING array.
316
find_string_in_array()
318
needle The string to search for
321
The last LEX_STRING in the array should have str member set to NULL
328
int find_string_in_array(LEX_STRING * const haystack, LEX_STRING * const needle,
329
const CHARSET_INFO * const cs)
331
const LEX_STRING *pos;
332
for (pos= haystack; pos->str; pos++)
333
if (!cs->coll->strnncollsp(cs, (uchar *) pos->str, pos->length,
334
(uchar *) needle->str, needle->length, 0))
336
return (pos - haystack);