~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/strfunc.cc

Removed DBUG symbols and fixed TRUE/FALSE

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/* Some useful string utility functions used by the MySQL server */
17
 
#include <drizzled/server_includes.h>
 
17
 
 
18
#include "mysql_priv.h"
18
19
 
19
20
/*
20
21
  Return bitmap for strings used in a set
37
38
 
38
39
static const char field_separator=',';
39
40
 
40
 
uint64_t find_set(TYPELIB *lib, const char *str, uint32_t length,
41
 
                  const CHARSET_INFO * const cs,
42
 
                  char **err_pos, uint32_t *err_len, bool *set_warning)
 
41
ulonglong find_set(TYPELIB *lib, const char *str, uint length, CHARSET_INFO *cs,
 
42
                   char **err_pos, uint *err_len, bool *set_warning)
43
43
{
44
 
  const CHARSET_INFO * const strip= cs ? cs : &my_charset_utf8_general_ci;
 
44
  CHARSET_INFO *strip= cs ? cs : &my_charset_latin1;
45
45
  const char *end= str + strip->cset->lengthsp(strip, str, length);
46
 
  uint64_t found= 0;
 
46
  ulonglong found= 0;
47
47
  *err_pos= 0;                  // No error yet
48
48
  if (str != end)
49
49
  {
51
51
    for (;;)
52
52
    {
53
53
      const char *pos= start;
54
 
      uint32_t var_len;
 
54
      uint 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 unsigned char *) pos, 
63
 
                                               (const unsigned char *) end)) < 1)
 
62
          if ((mblen= cs->cset->mb_wc(cs, &wc, (const uchar *) pos, 
 
63
                                               (const uchar *) 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
 
      uint32_t find= cs ? find_type2(lib, start, var_len, cs) :
 
72
      uint 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
      {
78
78
        *set_warning= 1;
79
79
      }
80
80
      else
81
 
        found|= ((int64_t) 1 << (find - 1));
 
81
        found|= ((longlong) 1 << (find - 1));
82
82
      if (pos >= end)
83
83
        break;
84
84
      start= pos + mblen;
104
104
  > 0 position in TYPELIB->type_names +1
105
105
*/
106
106
 
107
 
uint32_t find_type(const TYPELIB *lib, const char *find, uint32_t length,
 
107
uint find_type(const TYPELIB *lib, const char *find, uint length,
108
108
               bool part_match)
109
109
{
110
 
  uint32_t found_count=0, found_pos=0;
 
110
  uint 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 (uint32_t pos=0 ; (j=lib->type_names[pos++]) ; )
 
114
  for (uint 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
 
uint32_t find_type2(const TYPELIB *typelib, const char *x, uint32_t length,
149
 
                const CHARSET_INFO * const cs)
 
148
uint find_type2(const TYPELIB *typelib, const char *x, uint length,
 
149
                CHARSET_INFO *cs)
150
150
{
151
151
  int pos;
152
152
  const char *j;
 
153
  DBUG_ENTER("find_type2");
 
154
  DBUG_PRINT("enter",("x: '%.*s'  lib: 0x%lx", length, x, (long) typelib));
153
155
 
154
156
  if (!typelib->count)
155
157
  {
156
 
    return(0);
 
158
    DBUG_PRINT("exit",("no count"));
 
159
    DBUG_RETURN(0);
157
160
  }
158
161
 
159
162
  for (pos=0 ; (j=typelib->type_names[pos]) ; pos++)
160
163
  {
161
 
    if (!my_strnncoll(cs, (const unsigned char*) x, length,
162
 
                          (const unsigned char*) j, typelib->type_lengths[pos]))
163
 
      return(pos+1);
 
164
    if (!my_strnncoll(cs, (const uchar*) x, length,
 
165
                          (const uchar*) j, typelib->type_lengths[pos]))
 
166
      DBUG_RETURN(pos+1);
164
167
  }
165
 
  return(0);
 
168
  DBUG_PRINT("exit",("Couldn't find type"));
 
169
  DBUG_RETURN(0);
166
170
} /* find_type */
167
171
 
168
172
 
181
185
 
182
186
void unhex_type2(TYPELIB *interval)
183
187
{
184
 
  for (uint32_t pos= 0; pos < interval->count; pos++)
 
188
  for (uint pos= 0; pos < interval->count; pos++)
185
189
  {
186
190
    char *from, *to;
187
191
    for (from= to= (char*) interval->type_names[pos]; *from; )
219
223
         end_of_word will point to separator character/end in 'val'
220
224
*/
221
225
 
222
 
uint32_t check_word(TYPELIB *lib, const char *val, const char *end,
 
226
uint check_word(TYPELIB *lib, const char *val, const char *end,
223
227
                const char **end_of_word)
224
228
{
225
229
  int res;
226
230
  const char *ptr;
227
231
 
228
232
  /* Fiend end of word */
229
 
  for (ptr= val ; ptr < end && my_isalpha(&my_charset_utf8_general_ci, *ptr) ; ptr++)
 
233
  for (ptr= val ; ptr < end && my_isalpha(&my_charset_latin1, *ptr) ; ptr++)
230
234
    ;
231
235
  if ((res=find_type(lib, val, (uint) (ptr - val), 1)) > 0)
232
236
    *end_of_word= ptr;
254
258
*/
255
259
 
256
260
 
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)
 
261
uint strconvert(CHARSET_INFO *from_cs, const char *from,
 
262
                CHARSET_INFO *to_cs, char *to, uint to_length, uint *errors)
259
263
{
260
264
  int cnvres;
261
265
  my_wc_t wc;
262
266
  char *to_start= to;
263
 
  unsigned char *to_end= (unsigned char*) to + to_length - 1;
 
267
  uchar *to_end= (uchar*) to + to_length - 1;
264
268
  my_charset_conv_mb_wc mb_wc= from_cs->cset->mb_wc;
265
269
  my_charset_conv_wc_mb wc_mb= to_cs->cset->wc_mb;
266
 
  uint32_t error_count= 0;
 
270
  uint error_count= 0;
267
271
 
268
272
  while (1)
269
273
  {
274
278
        with error because of unexpected '\0' character.
275
279
    */
276
280
    if ((cnvres= (*mb_wc)(from_cs, &wc,
277
 
                          (unsigned char*) from, (unsigned char*) from + 10)) > 0)
 
281
                          (uchar*) from, (uchar*) from + 10)) > 0)
278
282
    {
279
283
      if (!wc)
280
284
        break;
291
295
 
292
296
outp:
293
297
 
294
 
    if ((cnvres= (*wc_mb)(to_cs, wc, (unsigned char*) to, to_end)) > 0)
 
298
    if ((cnvres= (*wc_mb)(to_cs, wc, (uchar*) to, to_end)) > 0)
295
299
      to+= cnvres;
296
300
    else if (cnvres == MY_CS_ILUNI && wc != '?')
297
301
    {
304
308
  }
305
309
  *to= '\0';
306
310
  *errors= error_count;
307
 
  return (uint32_t) (to - to_start);
 
311
  return (uint32) (to - to_start);
308
312
 
309
313
}
310
314
 
326
330
*/
327
331
 
328
332
int find_string_in_array(LEX_STRING * const haystack, LEX_STRING * const needle,
329
 
                         const CHARSET_INFO * const cs)
 
333
                         CHARSET_INFO * const cs)
330
334
{
331
335
  const LEX_STRING *pos;
332
336
  for (pos= haystack; pos->str; pos++)
333
 
    if (!cs->coll->strnncollsp(cs, (unsigned char *) pos->str, pos->length,
334
 
                               (unsigned char *) needle->str, needle->length, 0))
 
337
    if (!cs->coll->strnncollsp(cs, (uchar *) pos->str, pos->length,
 
338
                               (uchar *) needle->str, needle->length, 0))
335
339
    {
336
340
      return (pos - haystack);
337
341
    }