~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/strfunc.cc

MergedĀ inĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
  *err_pos= 0;                  // No error yet
48
48
  if (str != end)
49
49
  {
50
 
    const char *start= str;    
 
50
    const char *start= str;
51
51
    for (;;)
52
52
    {
53
53
      const char *pos= start;
54
54
      uint32_t var_len;
55
55
      int mblen= 1;
56
56
 
57
 
      if (cs && cs->mbminlen > 1)
58
 
      {
59
 
        for ( ; pos < end; pos+= mblen)
60
 
        {
61
 
          my_wc_t wc;
62
 
          if ((mblen= cs->cset->mb_wc(cs, &wc, (const unsigned char *) pos, 
63
 
                                               (const unsigned char *) end)) < 1)
64
 
            mblen= 1; // Not to hang on a wrong multibyte sequence
65
 
          if (wc == (my_wc_t) field_separator)
66
 
            break;
67
 
        }
68
 
      }
69
 
      else
70
 
        for (; pos != end && *pos != field_separator; pos++) ;
71
 
      var_len= (uint) (pos - start);
 
57
      for (; pos != end && *pos != field_separator; pos++) 
 
58
      {}
 
59
      var_len= (uint32_t) (pos - start);
72
60
      uint32_t find= cs ? find_type2(lib, start, var_len, cs) :
73
61
                      find_type(lib, start, var_len, (bool) 0);
74
62
      if (!find)
113
101
  const char *j;
114
102
  for (uint32_t pos=0 ; (j=lib->type_names[pos++]) ; )
115
103
  {
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++) ;
119
107
    if (i == end)
120
108
    {
228
216
  /* Fiend end of word */
229
217
  for (ptr= val ; ptr < end && my_isalpha(&my_charset_utf8_general_ci, *ptr) ; ptr++)
230
218
    ;
231
 
  if ((res=find_type(lib, val, (uint) (ptr - val), 1)) > 0)
 
219
  if ((res=find_type(lib, val, (uint32_t) (ptr - val), 1)) > 0)
232
220
    *end_of_word= ptr;
233
221
  return res;
234
222
}
235
223
 
236
224
 
237
225
/*
238
 
  Converts a string between character sets
239
 
 
240
 
  SYNOPSIS
241
 
    strconvert()
242
 
    from_cs       source character set
243
 
    from          source, a null terminated string
244
 
    to            destination buffer
245
 
    to_length     destination buffer length
246
 
 
247
 
  NOTES
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'.
251
 
 
252
 
  RETURN VALUES
253
 
    result string length
254
 
*/
255
 
 
256
 
 
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
 
{
260
 
  int cnvres;
261
 
  my_wc_t wc;
262
 
  char *to_start= to;
263
 
  unsigned char *to_end= (unsigned char*) 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;
266
 
  uint32_t error_count= 0;
267
 
 
268
 
  while (1)
269
 
  {
270
 
    /*
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.
275
 
    */
276
 
    if ((cnvres= (*mb_wc)(from_cs, &wc,
277
 
                          (unsigned char*) from, (unsigned char*) from + 10)) > 0)
278
 
    {
279
 
      if (!wc)
280
 
        break;
281
 
      from+= cnvres;
282
 
    }
283
 
    else if (cnvres == MY_CS_ILSEQ)
284
 
    {
285
 
      error_count++;
286
 
      from++;
287
 
      wc= '?';
288
 
    }
289
 
    else
290
 
      break; // Impossible char.
291
 
 
292
 
outp:
293
 
 
294
 
    if ((cnvres= (*wc_mb)(to_cs, wc, (unsigned char*) to, to_end)) > 0)
295
 
      to+= cnvres;
296
 
    else if (cnvres == MY_CS_ILUNI && wc != '?')
297
 
    {
298
 
      error_count++;
299
 
      wc= '?';
300
 
      goto outp;
301
 
    }
302
 
    else
303
 
      break;
304
 
  }
305
 
  *to= '\0';
306
 
  *errors= error_count;
307
 
  return (uint32_t) (to - to_start);
308
 
 
309
 
}
310
 
 
311
 
 
312
 
/*
313
226
  Searches for a LEX_STRING in an LEX_STRING array.
314
227
 
315
228
  SYNOPSIS