~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/strfunc.cc

Merged in changes from Andrey.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
 
38
38
static const char field_separator=',';
39
39
 
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)
43
43
{
44
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);
51
51
    for (;;)
52
52
    {
53
53
      const char *pos= start;
54
 
      uint var_len;
 
54
      uint32_t var_len;
55
55
      int mblen= 1;
56
56
 
57
57
      if (cs && cs->mbminlen > 1)
59
59
        for ( ; pos < end; pos+= mblen)
60
60
        {
61
61
          my_wc_t wc;
62
 
          if ((mblen= cs->cset->mb_wc(cs, &wc, (const uchar *) pos, 
63
 
                                               (const uchar *) end)) < 1)
 
62
          if ((mblen= cs->cset->mb_wc(cs, &wc, (const unsigned char *) pos, 
 
63
                                               (const unsigned char *) end)) < 1)
64
64
            mblen= 1; // Not to hang on a wrong multibyte sequence
65
65
          if (wc == (my_wc_t) field_separator)
66
66
            break;
69
69
      else
70
70
        for (; pos != end && *pos != field_separator; pos++) ;
71
71
      var_len= (uint) (pos - start);
72
 
      uint find= cs ? find_type2(lib, start, var_len, cs) :
 
72
      uint32_t find= cs ? find_type2(lib, start, var_len, cs) :
73
73
                      find_type(lib, start, var_len, (bool) 0);
74
74
      if (!find)
75
75
      {
104
104
  > 0 position in TYPELIB->type_names +1
105
105
*/
106
106
 
107
 
uint find_type(const TYPELIB *lib, const char *find, uint length,
 
107
uint32_t find_type(const TYPELIB *lib, const char *find, uint32_t length,
108
108
               bool part_match)
109
109
{
110
 
  uint found_count=0, found_pos=0;
 
110
  uint32_t found_count=0, found_pos=0;
111
111
  const char *end= find+length;
112
112
  const char *i;
113
113
  const char *j;
114
 
  for (uint pos=0 ; (j=lib->type_names[pos++]) ; )
 
114
  for (uint32_t pos=0 ; (j=lib->type_names[pos++]) ; )
115
115
  {
116
116
    for (i=find ; i != end && 
117
117
           my_toupper(system_charset_info,*i) == 
145
145
    >0  Offset+1 in typelib for matched string
146
146
*/
147
147
 
148
 
uint find_type2(const TYPELIB *typelib, const char *x, uint length,
 
148
uint32_t find_type2(const TYPELIB *typelib, const char *x, uint32_t length,
149
149
                const CHARSET_INFO * const cs)
150
150
{
151
151
  int pos;
158
158
 
159
159
  for (pos=0 ; (j=typelib->type_names[pos]) ; pos++)
160
160
  {
161
 
    if (!my_strnncoll(cs, (const uchar*) x, length,
162
 
                          (const uchar*) j, typelib->type_lengths[pos]))
 
161
    if (!my_strnncoll(cs, (const unsigned char*) x, length,
 
162
                          (const unsigned char*) j, typelib->type_lengths[pos]))
163
163
      return(pos+1);
164
164
  }
165
165
  return(0);
181
181
 
182
182
void unhex_type2(TYPELIB *interval)
183
183
{
184
 
  for (uint pos= 0; pos < interval->count; pos++)
 
184
  for (uint32_t pos= 0; pos < interval->count; pos++)
185
185
  {
186
186
    char *from, *to;
187
187
    for (from= to= (char*) interval->type_names[pos]; *from; )
219
219
         end_of_word will point to separator character/end in 'val'
220
220
*/
221
221
 
222
 
uint check_word(TYPELIB *lib, const char *val, const char *end,
 
222
uint32_t check_word(TYPELIB *lib, const char *val, const char *end,
223
223
                const char **end_of_word)
224
224
{
225
225
  int res;
254
254
*/
255
255
 
256
256
 
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)
 
257
uint32_t strconvert(const CHARSET_INFO * const from_cs, const char *from,
 
258
                const CHARSET_INFO * const to_cs, char *to, uint32_t to_length, uint32_t *errors)
259
259
{
260
260
  int cnvres;
261
261
  my_wc_t wc;
262
262
  char *to_start= to;
263
 
  uchar *to_end= (uchar*) to + to_length - 1;
 
263
  unsigned char *to_end= (unsigned char*) to + to_length - 1;
264
264
  my_charset_conv_mb_wc mb_wc= from_cs->cset->mb_wc;
265
265
  my_charset_conv_wc_mb wc_mb= to_cs->cset->wc_mb;
266
 
  uint error_count= 0;
 
266
  uint32_t error_count= 0;
267
267
 
268
268
  while (1)
269
269
  {
274
274
        with error because of unexpected '\0' character.
275
275
    */
276
276
    if ((cnvres= (*mb_wc)(from_cs, &wc,
277
 
                          (uchar*) from, (uchar*) from + 10)) > 0)
 
277
                          (unsigned char*) from, (unsigned char*) from + 10)) > 0)
278
278
    {
279
279
      if (!wc)
280
280
        break;
291
291
 
292
292
outp:
293
293
 
294
 
    if ((cnvres= (*wc_mb)(to_cs, wc, (uchar*) to, to_end)) > 0)
 
294
    if ((cnvres= (*wc_mb)(to_cs, wc, (unsigned char*) to, to_end)) > 0)
295
295
      to+= cnvres;
296
296
    else if (cnvres == MY_CS_ILUNI && wc != '?')
297
297
    {
330
330
{
331
331
  const LEX_STRING *pos;
332
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))
 
333
    if (!cs->coll->strnncollsp(cs, (unsigned char *) pos->str, pos->length,
 
334
                               (unsigned char *) needle->str, needle->length, 0))
335
335
    {
336
336
      return (pos - haystack);
337
337
    }