~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/sql_string.cc

Merged.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* This file is originally from the mysql distribution. Coded by monty */
17
17
 
18
 
#include "global.h"
19
 
#include <mysys/my_sys.h>
20
 
#include <mystrings/m_string.h>
 
18
#ifdef USE_PRAGMA_IMPLEMENTATION
 
19
#pragma implementation                          // gcc: Class implementation
 
20
#endif
21
21
 
22
 
#include <algorithm>
 
22
#include <my_global.h>
 
23
#include <my_sys.h>
 
24
#include <m_string.h>
 
25
#include <m_ctype.h>
23
26
 
24
27
/*
25
28
  The following extern declarations are ok as these are interface functions
26
29
  required by the string function
27
30
*/
28
31
 
29
 
extern unsigned char* sql_alloc(unsigned size);
 
32
extern uchar* sql_alloc(unsigned size);
30
33
extern void sql_element_free(void *ptr);
31
34
 
32
35
#include "sql_string.h"
35
38
** String functions
36
39
*****************************************************************************/
37
40
 
38
 
bool String::real_alloc(uint32_t arg_length)
 
41
bool String::real_alloc(uint32 arg_length)
39
42
{
40
43
  arg_length=ALIGN_SIZE(arg_length+1);
41
44
  str_length=0;
57
60
** (for C functions)
58
61
*/
59
62
 
60
 
bool String::realloc(uint32_t alloc_length)
 
63
bool String::realloc(uint32 alloc_length)
61
64
{
62
 
  uint32_t len=ALIGN_SIZE(alloc_length+1);
 
65
  uint32 len=ALIGN_SIZE(alloc_length+1);
63
66
  if (Alloced_length < len)
64
67
  {
65
68
    char *new_ptr;
89
92
  return false;
90
93
}
91
94
 
92
 
bool String::set_int(int64_t num, bool unsigned_flag, const CHARSET_INFO * const cs)
 
95
bool String::set_int(int64_t num, bool unsigned_flag, CHARSET_INFO *cs)
93
96
{
94
 
  uint32_t l=20*cs->mbmaxlen+1;
 
97
  uint l=20*cs->mbmaxlen+1;
95
98
  int base= unsigned_flag ? 10 : -10;
96
99
 
97
100
  if (alloc(l))
98
101
    return true;
99
 
  str_length=(uint32_t) (cs->cset->int64_t10_to_str)(cs,Ptr,l,base,num);
 
102
  str_length=(uint32) (cs->cset->int64_t10_to_str)(cs,Ptr,l,base,num);
100
103
  str_charset=cs;
101
104
  return false;
102
105
}
103
106
 
104
 
bool String::set_real(double num,uint32_t decimals, const CHARSET_INFO * const cs)
 
107
bool String::set_real(double num,uint decimals, CHARSET_INFO *cs)
105
108
{
106
109
  char buff[FLOATING_POINT_BUFFER];
107
 
  uint32_t dummy_errors;
 
110
  uint dummy_errors;
108
111
  size_t len;
109
112
 
110
113
  str_charset=cs;
111
114
  if (decimals >= NOT_FIXED_DEC)
112
115
  {
113
116
    len= my_gcvt(num, MY_GCVT_ARG_DOUBLE, sizeof(buff) - 1, buff, NULL);
114
 
    return copy(buff, len, &my_charset_utf8_general_ci, cs, &dummy_errors);
 
117
    return copy(buff, len, &my_charset_latin1, cs, &dummy_errors);
115
118
  }
116
119
  len= my_fcvt(num, decimals, buff, NULL);
117
 
  return copy(buff, (uint32_t) len, &my_charset_utf8_general_ci, cs,
 
120
  return copy(buff, (uint32) len, &my_charset_latin1, cs,
118
121
              &dummy_errors);
119
122
}
120
123
 
134
137
  if (alloc(str.str_length))
135
138
    return true;
136
139
  str_length=str.str_length;
137
 
  memmove(Ptr, str.Ptr, str_length);            // May be overlapping
 
140
  bmove(Ptr,str.Ptr,str_length);                // May be overlapping
138
141
  Ptr[str_length]=0;
139
142
  str_charset=str.str_charset;
140
143
  return false;
141
144
}
142
145
 
143
 
bool String::copy(const char *str,uint32_t arg_length, const CHARSET_INFO * const cs)
 
146
bool String::copy(const char *str,uint32 arg_length, CHARSET_INFO *cs)
144
147
{
145
148
  if (alloc(arg_length))
146
149
    return true;
162
165
  arg_length            Length of string to copy.
163
166
  from_cs               Character set to copy from
164
167
  to_cs                 Character set to copy to
165
 
  uint32_t *offset      Returns number of unaligned characters.
 
168
  uint32 *offset        Returns number of unaligned characters.
166
169
 
167
170
  RETURN
168
171
   0  No conversion needed
174
177
  character_set_results is NULL.
175
178
*/
176
179
 
177
 
bool String::needs_conversion(uint32_t arg_length,
178
 
                              const CHARSET_INFO * const from_cs,
179
 
                              const CHARSET_INFO * const to_cs,
180
 
                              uint32_t *offset)
 
180
bool String::needs_conversion(uint32 arg_length,
 
181
                              CHARSET_INFO *from_cs,
 
182
                              CHARSET_INFO *to_cs,
 
183
                              uint32 *offset)
181
184
{
182
185
  *offset= 0;
183
186
  if (!to_cs ||
216
219
    1  error
217
220
*/
218
221
 
219
 
bool String::copy_aligned(const char *str,uint32_t arg_length, uint32_t offset,
220
 
                          const CHARSET_INFO * const cs)
 
222
bool String::copy_aligned(const char *str,uint32 arg_length, uint32 offset,
 
223
                          CHARSET_INFO *cs)
221
224
{
222
225
  /* How many bytes are in incomplete character */
223
226
  offset= cs->mbmaxlen - offset; /* How many zeros we should prepend */
224
227
  assert(offset && offset != cs->mbmaxlen);
225
228
 
226
 
  uint32_t aligned_length= arg_length + offset;
 
229
  uint32 aligned_length= arg_length + offset;
227
230
  if (alloc(aligned_length))
228
231
    return true;
229
232
  
232
235
    If we add little-endian UCS-2 sometimes, this code
233
236
    will be more complicated. But it's OK for now.
234
237
  */
235
 
  memset(Ptr, 0, offset);
 
238
  bzero((char*) Ptr, offset);
236
239
  memcpy(Ptr + offset, str, arg_length);
237
240
  Ptr[aligned_length]=0;
238
241
  /* str_length is always >= 0 as arg_length is != 0 */
242
245
}
243
246
 
244
247
 
245
 
bool String::set_or_copy_aligned(const char *str,uint32_t arg_length,
246
 
                                 const CHARSET_INFO * const cs)
 
248
bool String::set_or_copy_aligned(const char *str,uint32 arg_length,
 
249
                                 CHARSET_INFO *cs)
247
250
{
248
251
  /* How many bytes are in incomplete character */
249
 
  uint32_t offset= (arg_length % cs->mbminlen); 
 
252
  uint32 offset= (arg_length % cs->mbminlen); 
250
253
  
251
254
  if (!offset) /* All characters are complete, just copy */
252
255
  {
258
261
 
259
262
        /* Copy with charset conversion */
260
263
 
261
 
bool String::copy(const char *str, uint32_t arg_length,
262
 
                          const CHARSET_INFO * const from_cs,
263
 
                                  const CHARSET_INFO * const to_cs, uint32_t *errors)
 
264
bool String::copy(const char *str, uint32 arg_length,
 
265
                  CHARSET_INFO *from_cs, CHARSET_INFO *to_cs, uint *errors)
264
266
{
265
 
  uint32_t offset;
 
267
  uint32 offset;
266
268
  if (!needs_conversion(arg_length, from_cs, to_cs, &offset))
267
269
  {
268
270
    *errors= 0;
273
275
    *errors= 0;
274
276
    return copy_aligned(str, arg_length, offset, to_cs);
275
277
  }
276
 
  uint32_t new_length= to_cs->mbmaxlen*arg_length;
 
278
  uint32 new_length= to_cs->mbmaxlen*arg_length;
277
279
  if (alloc(new_length))
278
280
    return true;
279
281
  str_length=copy_and_convert((char*) Ptr, new_length, to_cs,
302
304
 
303
305
*/
304
306
 
305
 
bool String::set_ascii(const char *str, uint32_t arg_length)
 
307
bool String::set_ascii(const char *str, uint32 arg_length)
306
308
{
307
309
  if (str_charset->mbminlen == 1)
308
310
  {
309
311
    set(str, arg_length, str_charset);
310
312
    return 0;
311
313
  }
312
 
  uint32_t dummy_errors;
313
 
  return copy(str, arg_length, &my_charset_utf8_general_ci, str_charset, &dummy_errors);
 
314
  uint dummy_errors;
 
315
  return copy(str, arg_length, &my_charset_latin1, str_charset, &dummy_errors);
314
316
}
315
317
 
316
318
 
317
319
/* This is used by mysql.cc */
318
320
 
319
 
bool String::fill(uint32_t max_length,char fill_char)
 
321
bool String::fill(uint32 max_length,char fill_char)
320
322
{
321
323
  if (str_length > max_length)
322
324
    Ptr[str_length=max_length]=0;
324
326
  {
325
327
    if (realloc(max_length))
326
328
      return true;
327
 
    memset(Ptr+str_length, fill_char, max_length-str_length);
 
329
    bfill(Ptr+str_length,max_length-str_length,fill_char);
328
330
    str_length=max_length;
329
331
  }
330
332
  return false;
331
333
}
332
334
 
 
335
void String::strip_sp()
 
336
{
 
337
   while (str_length && my_isspace(str_charset,Ptr[str_length-1]))
 
338
    str_length--;
 
339
}
 
340
 
333
341
bool String::append(const String &s)
334
342
{
335
343
  if (s.length())
347
355
  Append an ASCII string to the a string of the current character set
348
356
*/
349
357
 
350
 
bool String::append(const char *s,uint32_t arg_length)
 
358
bool String::append(const char *s,uint32 arg_length)
351
359
{
352
360
  if (!arg_length)
353
361
    return false;
357
365
  */
358
366
  if (str_charset->mbminlen > 1)
359
367
  {
360
 
    uint32_t add_length=arg_length * str_charset->mbmaxlen;
361
 
    uint32_t dummy_errors;
 
368
    uint32 add_length=arg_length * str_charset->mbmaxlen;
 
369
    uint dummy_errors;
362
370
    if (realloc(str_length+ add_length))
363
371
      return true;
364
372
    str_length+= copy_and_convert(Ptr+str_length, add_length, str_charset,
365
 
                                  s, arg_length, &my_charset_utf8_general_ci,
 
373
                                  s, arg_length, &my_charset_latin1,
366
374
                                  &dummy_errors);
367
375
    return false;
368
376
  }
393
401
  with character set recoding
394
402
*/
395
403
 
396
 
bool String::append(const char *s,uint32_t arg_length, const CHARSET_INFO * const cs)
 
404
bool String::append(const char *s,uint32 arg_length, CHARSET_INFO *cs)
397
405
{
398
 
  uint32_t dummy_offset;
 
406
  uint32 dummy_offset;
399
407
  
400
408
  if (needs_conversion(arg_length, cs, str_charset, &dummy_offset))
401
409
  {
402
 
    uint32_t add_length= arg_length / cs->mbminlen * str_charset->mbmaxlen;
403
 
    uint32_t dummy_errors;
 
410
    uint32 add_length= arg_length / cs->mbminlen * str_charset->mbmaxlen;
 
411
    uint dummy_errors;
404
412
    if (realloc(str_length + add_length)) 
405
413
      return true;
406
414
    str_length+= copy_and_convert(Ptr+str_length, add_length, str_charset,
417
425
}
418
426
 
419
427
 
420
 
bool String::append(IO_CACHE* file, uint32_t arg_length)
 
428
bool String::append(IO_CACHE* file, uint32 arg_length)
421
429
{
422
430
  if (realloc(str_length+arg_length))
423
431
    return true;
424
 
  if (my_b_read(file, (unsigned char*) Ptr + str_length, arg_length))
 
432
  if (my_b_read(file, (uchar*) Ptr + str_length, arg_length))
425
433
  {
426
434
    shrink(str_length);
427
435
    return true;
430
438
  return false;
431
439
}
432
440
 
433
 
bool String::append_with_prefill(const char *s,uint32_t arg_length,
434
 
                 uint32_t full_length, char fill_char)
 
441
bool String::append_with_prefill(const char *s,uint32 arg_length,
 
442
                 uint32 full_length, char fill_char)
435
443
{
436
444
  int t_length= arg_length > full_length ? arg_length : full_length;
437
445
 
440
448
  t_length= full_length - arg_length;
441
449
  if (t_length > 0)
442
450
  {
443
 
    memset(Ptr+str_length, fill_char, t_length);
 
451
    bfill(Ptr+str_length, t_length, fill_char);
444
452
    str_length=str_length + t_length;
445
453
  }
446
454
  append(s, arg_length);
447
455
  return false;
448
456
}
449
457
 
450
 
uint32_t String::numchars()
 
458
uint32 String::numchars()
451
459
{
452
460
  return str_charset->cset->numchars(str_charset, Ptr, Ptr+str_length);
453
461
}
454
462
 
455
 
int String::charpos(int i,uint32_t offset)
 
463
int String::charpos(int i,uint32 offset)
456
464
{
457
465
  if (i <= 0)
458
466
    return i;
459
467
  return str_charset->cset->charpos(str_charset,Ptr+offset,Ptr+str_length,i);
460
468
}
461
469
 
462
 
int String::strstr(const String &s,uint32_t offset)
 
470
int String::strstr(const String &s,uint32 offset)
463
471
{
464
472
  if (s.length()+offset <= str_length)
465
473
  {
490
498
** Search string from end. Offset is offset to the end of string
491
499
*/
492
500
 
493
 
int String::strrstr(const String &s,uint32_t offset)
 
501
int String::strrstr(const String &s,uint32 offset)
494
502
{
495
503
  if (s.length() <= offset && offset <= str_length)
496
504
  {
522
530
  If wrong parameter or not enough memory, do nothing
523
531
*/
524
532
 
525
 
bool String::replace(uint32_t offset,uint32_t arg_length,const String &to)
 
533
bool String::replace(uint32 offset,uint32 arg_length,const String &to)
526
534
{
527
535
  return replace(offset,arg_length,to.ptr(),to.length());
528
536
}
529
537
 
530
 
bool String::replace(uint32_t offset,uint32_t arg_length,
531
 
                     const char *to, uint32_t to_length)
 
538
bool String::replace(uint32 offset,uint32 arg_length,
 
539
                     const char *to, uint32 to_length)
532
540
{
533
541
  long diff = (long) to_length-(long) arg_length;
534
542
  if (offset+arg_length <= str_length)
537
545
    {
538
546
      if (to_length)
539
547
        memcpy(Ptr+offset,to,to_length);
540
 
      memcpy(Ptr+offset+to_length, Ptr+offset+arg_length,
541
 
             str_length-offset-arg_length);
 
548
      bmove(Ptr+offset+to_length,Ptr+offset+arg_length,
 
549
            str_length-offset-arg_length);
542
550
    }
543
551
    else
544
552
    {
545
553
      if (diff)
546
554
      {
547
 
        if (realloc(str_length+(uint32_t) diff))
 
555
        if (realloc(str_length+(uint32) diff))
548
556
          return true;
549
 
        bmove_upp((unsigned char*) Ptr+str_length+diff, (unsigned char*) Ptr+str_length,
 
557
        bmove_upp((uchar*) Ptr+str_length+diff, (uchar*) Ptr+str_length,
550
558
                  str_length-offset-arg_length);
551
559
      }
552
560
      if (to_length)
553
561
        memcpy(Ptr+offset,to,to_length);
554
562
    }
555
 
    str_length+=(uint32_t) diff;
 
563
    str_length+=(uint32) diff;
556
564
  }
557
565
  return false;
558
566
}
559
567
 
560
568
 
561
569
// added by Holyfoot for "geometry" needs
562
 
int String::reserve(uint32_t space_needed, uint32_t grow_by)
 
570
int String::reserve(uint32 space_needed, uint32 grow_by)
563
571
{
564
572
  if (Alloced_length < str_length + space_needed)
565
573
  {
566
 
    if (realloc(Alloced_length + cmax(space_needed, grow_by) - 1))
 
574
    if (realloc(Alloced_length + max(space_needed, grow_by) - 1))
567
575
      return true;
568
576
  }
569
577
  return false;
570
578
}
571
579
 
572
 
void String::qs_append(const char *str, uint32_t len)
 
580
void String::qs_append(const char *str, uint32 len)
573
581
{
574
582
  memcpy(Ptr + str_length, str, len + 1);
575
583
  str_length += len;
595
603
  str_length+= (int) (end-buff);
596
604
}
597
605
 
598
 
void String::qs_append(uint32_t i)
 
606
void String::qs_append(uint i)
599
607
{
600
608
  char *buff= Ptr + str_length;
601
609
  char *end= int10_to_str(i, buff, 10);
621
629
*/
622
630
 
623
631
 
624
 
int sortcmp(const String *s,const String *t, const CHARSET_INFO * const cs)
 
632
int sortcmp(const String *s,const String *t, CHARSET_INFO *cs)
625
633
{
626
634
 return cs->coll->strnncollsp(cs,
627
 
                              (unsigned char *) s->ptr(),s->length(),
628
 
                              (unsigned char *) t->ptr(),t->length(), 0);
 
635
                              (uchar *) s->ptr(),s->length(),
 
636
                              (uchar *) t->ptr(),t->length(), 0);
629
637
}
630
638
 
631
639
 
638
646
    t           Second string
639
647
 
640
648
  NOTE:
641
 
    Strings are compared as a stream of unsigned chars
 
649
    Strings are compared as a stream of uchars
642
650
 
643
651
  RETURN
644
652
  < 0   s < t
649
657
 
650
658
int stringcmp(const String *s,const String *t)
651
659
{
652
 
  uint32_t s_len=s->length(),t_len=t->length(),len=cmin(s_len,t_len);
 
660
  uint32 s_len=s->length(),t_len=t->length(),len=min(s_len,t_len);
653
661
  int cmp= memcmp(s->ptr(), t->ptr(), len);
654
662
  return (cmp) ? cmp : (int) (s_len - t_len);
655
663
}
656
664
 
657
665
 
658
 
String *copy_if_not_alloced(String *to,String *from,uint32_t from_length)
 
666
String *copy_if_not_alloced(String *to,String *from,uint32 from_length)
659
667
{
660
668
  if (from->Alloced_length >= from_length)
661
669
    return from;
666
674
  }
667
675
  if (to->realloc(from_length))
668
676
    return from;                                // Actually an error
669
 
  if ((to->str_length=cmin(from->str_length,from_length)))
 
677
  if ((to->str_length=min(from->str_length,from_length)))
670
678
    memcpy(to->Ptr,from->Ptr,to->str_length);
671
679
  to->str_charset=from->str_charset;
672
680
  return to;
696
704
*/
697
705
 
698
706
 
699
 
static uint32_t
700
 
copy_and_convert_extended(char *to, uint32_t to_length,
701
 
                          const CHARSET_INFO * const to_cs, 
702
 
                          const char *from, uint32_t from_length,
703
 
                          const CHARSET_INFO * const from_cs,
704
 
                          uint32_t *errors)
 
707
static uint32
 
708
copy_and_convert_extended(char *to, uint32 to_length, CHARSET_INFO *to_cs, 
 
709
                          const char *from, uint32 from_length,
 
710
                          CHARSET_INFO *from_cs,
 
711
                          uint *errors)
705
712
{
706
713
  int         cnvres;
707
714
  my_wc_t     wc;
708
 
  const unsigned char *from_end= (const unsigned char*) from+from_length;
 
715
  const uchar *from_end= (const uchar*) from+from_length;
709
716
  char *to_start= to;
710
 
  unsigned char *to_end= (unsigned char*) to+to_length;
 
717
  uchar *to_end= (uchar*) to+to_length;
711
718
  my_charset_conv_mb_wc mb_wc= from_cs->cset->mb_wc;
712
719
  my_charset_conv_wc_mb wc_mb= to_cs->cset->wc_mb;
713
 
  uint32_t error_count= 0;
 
720
  uint error_count= 0;
714
721
 
715
722
  while (1)
716
723
  {
717
 
    if ((cnvres= (*mb_wc)(from_cs, &wc, (unsigned char*) from,
 
724
    if ((cnvres= (*mb_wc)(from_cs, &wc, (uchar*) from,
718
725
                                      from_end)) > 0)
719
726
      from+= cnvres;
720
727
    else if (cnvres == MY_CS_ILSEQ)
737
744
      break;  // Not enough characters
738
745
 
739
746
outp:
740
 
    if ((cnvres= (*wc_mb)(to_cs, wc, (unsigned char*) to, to_end)) > 0)
 
747
    if ((cnvres= (*wc_mb)(to_cs, wc, (uchar*) to, to_end)) > 0)
741
748
      to+= cnvres;
742
749
    else if (cnvres == MY_CS_ILUNI && wc != '?')
743
750
    {
749
756
      break;
750
757
  }
751
758
  *errors= error_count;
752
 
  return (uint32_t) (to - to_start);
 
759
  return (uint32) (to - to_start);
753
760
}
754
761
 
755
762
 
756
763
/*
757
764
  Optimized for quick copying of ASCII characters in the range 0x00..0x7F.
758
765
*/
759
 
uint32_t
760
 
copy_and_convert(char *to, uint32_t to_length, const CHARSET_INFO * const to_cs, 
761
 
                 const char *from, uint32_t from_length,
762
 
                                 const CHARSET_INFO * const from_cs, uint32_t *errors)
 
766
uint32
 
767
copy_and_convert(char *to, uint32 to_length, CHARSET_INFO *to_cs, 
 
768
                 const char *from, uint32 from_length, CHARSET_INFO *from_cs,
 
769
                 uint *errors)
763
770
{
764
771
  /*
765
772
    If any of the character sets is not ASCII compatible,
769
776
    return copy_and_convert_extended(to, to_length, to_cs,
770
777
                                     from, from_length, from_cs, errors);
771
778
 
772
 
  uint32_t length= cmin(to_length, from_length), length2= length;
 
779
  uint32 length= min(to_length, from_length), length2= length;
773
780
 
774
781
#if defined(__i386__)
775
782
  /*
781
788
  */
782
789
  for ( ; length >= 4; length-= 4, from+= 4, to+= 4)
783
790
  {
784
 
    if ((*(uint32_t*)from) & 0x80808080)
 
791
    if ((*(uint32*)from) & 0x80808080)
785
792
      break;
786
 
    *((uint32_t*) to)= *((const uint32_t*) from);
 
793
    *((uint32*) to)= *((const uint32*) from);
787
794
  }
788
795
#endif
789
796
 
796
803
    }
797
804
    if (*((unsigned char*) from) > 0x7F) /* A non-ASCII character */
798
805
    {
799
 
      uint32_t copied_length= length2 - length;
 
806
      uint32 copied_length= length2 - length;
800
807
      to_length-= copied_length;
801
808
      from_length-= copied_length;
802
809
      return copied_length + copy_and_convert_extended(to, to_length,
833
840
*/
834
841
 
835
842
size_t
836
 
my_copy_with_hex_escaping(const CHARSET_INFO * const cs,
 
843
my_copy_with_hex_escaping(CHARSET_INFO *cs,
837
844
                          char *dst, size_t dstlen,
838
845
                          const char *src, size_t srclen)
839
846
{
901
908
*/
902
909
 
903
910
 
904
 
uint32_t
905
 
well_formed_copy_nchars(const CHARSET_INFO * const to_cs,
906
 
                        char *to, uint32_t to_length,
907
 
                        const CHARSET_INFO * const from_cs,
908
 
                        const char *from, uint32_t from_length,
909
 
                        uint32_t nchars,
 
911
uint32
 
912
well_formed_copy_nchars(CHARSET_INFO *to_cs,
 
913
                        char *to, uint to_length,
 
914
                        CHARSET_INFO *from_cs,
 
915
                        const char *from, uint from_length,
 
916
                        uint nchars,
910
917
                        const char **well_formed_error_pos,
911
918
                        const char **cannot_convert_error_pos,
912
919
                        const char **from_end_pos)
913
920
{
914
 
  uint32_t res;
 
921
  uint res;
915
922
 
916
923
  if ((to_cs == &my_charset_bin) || 
917
924
      (from_cs == &my_charset_bin) ||
928
935
 
929
936
    if (to_cs == &my_charset_bin)
930
937
    {
931
 
      res= cmin(cmin(nchars, to_length), from_length);
 
938
      res= min(min(nchars, to_length), from_length);
932
939
      memmove(to, from, res);
933
940
      *from_end_pos= from + res;
934
941
      *well_formed_error_pos= NULL;
937
944
    else
938
945
    {
939
946
      int well_formed_error;
940
 
      uint32_t from_offset;
 
947
      uint from_offset;
941
948
 
942
949
      if ((from_offset= (from_length % to_cs->mbminlen)) &&
943
950
          (from_cs == &my_charset_bin))
947
954
          INSERT INTO t1 (ucs2_column) VALUES (0x01);
948
955
          0x01 -> 0x0001
949
956
        */
950
 
        uint32_t pad_length= to_cs->mbminlen - from_offset;
951
 
        memset(to, 0, pad_length);
 
957
        uint pad_length= to_cs->mbminlen - from_offset;
 
958
        bzero(to, pad_length);
952
959
        memmove(to + pad_length, from, from_offset);
953
960
        nchars--;
954
961
        from+= from_offset;
974
981
    my_wc_t wc;
975
982
    my_charset_conv_mb_wc mb_wc= from_cs->cset->mb_wc;
976
983
    my_charset_conv_wc_mb wc_mb= to_cs->cset->wc_mb;
977
 
    const unsigned char *from_end= (const unsigned char*) from + from_length;
978
 
    unsigned char *to_end= (unsigned char*) to + to_length;
 
984
    const uchar *from_end= (const uchar*) from + from_length;
 
985
    uchar *to_end= (uchar*) to + to_length;
979
986
    char *to_start= to;
980
987
    *well_formed_error_pos= NULL;
981
988
    *cannot_convert_error_pos= NULL;
983
990
    for ( ; nchars; nchars--)
984
991
    {
985
992
      const char *from_prev= from;
986
 
      if ((cnvres= (*mb_wc)(from_cs, &wc, (unsigned char*) from, from_end)) > 0)
 
993
      if ((cnvres= (*mb_wc)(from_cs, &wc, (uchar*) from, from_end)) > 0)
987
994
        from+= cnvres;
988
995
      else if (cnvres == MY_CS_ILSEQ)
989
996
      {
1007
1014
        break;  // Not enough characters
1008
1015
 
1009
1016
outp:
1010
 
      if ((cnvres= (*wc_mb)(to_cs, wc, (unsigned char*) to, to_end)) > 0)
 
1017
      if ((cnvres= (*wc_mb)(to_cs, wc, (uchar*) to, to_end)) > 0)
1011
1018
        to+= cnvres;
1012
1019
      else if (cnvres == MY_CS_ILUNI && wc != '?')
1013
1020
      {
1025
1032
    *from_end_pos= from;
1026
1033
    res= to - to_start;
1027
1034
  }
1028
 
  return (uint32_t) res;
 
1035
  return (uint32) res;
1029
1036
}
1030
1037
 
1031
1038
 
1036
1043
  char *st= (char*)Ptr, *end= st+str_length;
1037
1044
  for (; st < end; st++)
1038
1045
  {
1039
 
    unsigned char c= *st;
 
1046
    uchar c= *st;
1040
1047
    switch (c)
1041
1048
    {
1042
1049
    case '\\':
1076
1083
 
1077
1084
void String::swap(String &s)
1078
1085
{
1079
 
  std::swap(Ptr, s.Ptr);
1080
 
  std::swap(str_length, s.str_length);
1081
 
  std::swap(Alloced_length, s.Alloced_length);
1082
 
  std::swap(alloced, s.alloced);
1083
 
  std::swap(str_charset, s.str_charset);
 
1086
  swap_variables(char *, Ptr, s.Ptr);
 
1087
  swap_variables(uint32, str_length, s.str_length);
 
1088
  swap_variables(uint32, Alloced_length, s.Alloced_length);
 
1089
  swap_variables(bool, alloced, s.alloced);
 
1090
  swap_variables(CHARSET_INFO*, str_charset, s.str_charset);
1084
1091
}