~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/sql_string.cc

  • Committer: Brian Aker
  • Date: 2008-07-22 18:31:32 UTC
  • Revision ID: brian@tangent.org-20080722183132-ne2ntl7g7mdf2eez
uint32 -> uin32_t

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
** String functions
39
39
*****************************************************************************/
40
40
 
41
 
bool String::real_alloc(uint32 arg_length)
 
41
bool String::real_alloc(uint32_t arg_length)
42
42
{
43
43
  arg_length=ALIGN_SIZE(arg_length+1);
44
44
  str_length=0;
60
60
** (for C functions)
61
61
*/
62
62
 
63
 
bool String::realloc(uint32 alloc_length)
 
63
bool String::realloc(uint32_t alloc_length)
64
64
{
65
 
  uint32 len=ALIGN_SIZE(alloc_length+1);
 
65
  uint32_t len=ALIGN_SIZE(alloc_length+1);
66
66
  if (Alloced_length < len)
67
67
  {
68
68
    char *new_ptr;
99
99
 
100
100
  if (alloc(l))
101
101
    return true;
102
 
  str_length=(uint32) (cs->cset->int64_t10_to_str)(cs,Ptr,l,base,num);
 
102
  str_length=(uint32_t) (cs->cset->int64_t10_to_str)(cs,Ptr,l,base,num);
103
103
  str_charset=cs;
104
104
  return false;
105
105
}
117
117
    return copy(buff, len, &my_charset_latin1, cs, &dummy_errors);
118
118
  }
119
119
  len= my_fcvt(num, decimals, buff, NULL);
120
 
  return copy(buff, (uint32) len, &my_charset_latin1, cs,
 
120
  return copy(buff, (uint32_t) len, &my_charset_latin1, cs,
121
121
              &dummy_errors);
122
122
}
123
123
 
143
143
  return false;
144
144
}
145
145
 
146
 
bool String::copy(const char *str,uint32 arg_length, CHARSET_INFO *cs)
 
146
bool String::copy(const char *str,uint32_t arg_length, CHARSET_INFO *cs)
147
147
{
148
148
  if (alloc(arg_length))
149
149
    return true;
165
165
  arg_length            Length of string to copy.
166
166
  from_cs               Character set to copy from
167
167
  to_cs                 Character set to copy to
168
 
  uint32 *offset        Returns number of unaligned characters.
 
168
  uint32_t *offset      Returns number of unaligned characters.
169
169
 
170
170
  RETURN
171
171
   0  No conversion needed
177
177
  character_set_results is NULL.
178
178
*/
179
179
 
180
 
bool String::needs_conversion(uint32 arg_length,
 
180
bool String::needs_conversion(uint32_t arg_length,
181
181
                              CHARSET_INFO *from_cs,
182
182
                              CHARSET_INFO *to_cs,
183
 
                              uint32 *offset)
 
183
                              uint32_t *offset)
184
184
{
185
185
  *offset= 0;
186
186
  if (!to_cs ||
219
219
    1  error
220
220
*/
221
221
 
222
 
bool String::copy_aligned(const char *str,uint32 arg_length, uint32 offset,
 
222
bool String::copy_aligned(const char *str,uint32_t arg_length, uint32_t offset,
223
223
                          CHARSET_INFO *cs)
224
224
{
225
225
  /* How many bytes are in incomplete character */
226
226
  offset= cs->mbmaxlen - offset; /* How many zeros we should prepend */
227
227
  assert(offset && offset != cs->mbmaxlen);
228
228
 
229
 
  uint32 aligned_length= arg_length + offset;
 
229
  uint32_t aligned_length= arg_length + offset;
230
230
  if (alloc(aligned_length))
231
231
    return true;
232
232
  
245
245
}
246
246
 
247
247
 
248
 
bool String::set_or_copy_aligned(const char *str,uint32 arg_length,
 
248
bool String::set_or_copy_aligned(const char *str,uint32_t arg_length,
249
249
                                 CHARSET_INFO *cs)
250
250
{
251
251
  /* How many bytes are in incomplete character */
252
 
  uint32 offset= (arg_length % cs->mbminlen); 
 
252
  uint32_t offset= (arg_length % cs->mbminlen); 
253
253
  
254
254
  if (!offset) /* All characters are complete, just copy */
255
255
  {
261
261
 
262
262
        /* Copy with charset conversion */
263
263
 
264
 
bool String::copy(const char *str, uint32 arg_length,
 
264
bool String::copy(const char *str, uint32_t arg_length,
265
265
                  CHARSET_INFO *from_cs, CHARSET_INFO *to_cs, uint *errors)
266
266
{
267
 
  uint32 offset;
 
267
  uint32_t offset;
268
268
  if (!needs_conversion(arg_length, from_cs, to_cs, &offset))
269
269
  {
270
270
    *errors= 0;
275
275
    *errors= 0;
276
276
    return copy_aligned(str, arg_length, offset, to_cs);
277
277
  }
278
 
  uint32 new_length= to_cs->mbmaxlen*arg_length;
 
278
  uint32_t new_length= to_cs->mbmaxlen*arg_length;
279
279
  if (alloc(new_length))
280
280
    return true;
281
281
  str_length=copy_and_convert((char*) Ptr, new_length, to_cs,
304
304
 
305
305
*/
306
306
 
307
 
bool String::set_ascii(const char *str, uint32 arg_length)
 
307
bool String::set_ascii(const char *str, uint32_t arg_length)
308
308
{
309
309
  if (str_charset->mbminlen == 1)
310
310
  {
318
318
 
319
319
/* This is used by mysql.cc */
320
320
 
321
 
bool String::fill(uint32 max_length,char fill_char)
 
321
bool String::fill(uint32_t max_length,char fill_char)
322
322
{
323
323
  if (str_length > max_length)
324
324
    Ptr[str_length=max_length]=0;
355
355
  Append an ASCII string to the a string of the current character set
356
356
*/
357
357
 
358
 
bool String::append(const char *s,uint32 arg_length)
 
358
bool String::append(const char *s,uint32_t arg_length)
359
359
{
360
360
  if (!arg_length)
361
361
    return false;
365
365
  */
366
366
  if (str_charset->mbminlen > 1)
367
367
  {
368
 
    uint32 add_length=arg_length * str_charset->mbmaxlen;
 
368
    uint32_t add_length=arg_length * str_charset->mbmaxlen;
369
369
    uint dummy_errors;
370
370
    if (realloc(str_length+ add_length))
371
371
      return true;
401
401
  with character set recoding
402
402
*/
403
403
 
404
 
bool String::append(const char *s,uint32 arg_length, CHARSET_INFO *cs)
 
404
bool String::append(const char *s,uint32_t arg_length, CHARSET_INFO *cs)
405
405
{
406
 
  uint32 dummy_offset;
 
406
  uint32_t dummy_offset;
407
407
  
408
408
  if (needs_conversion(arg_length, cs, str_charset, &dummy_offset))
409
409
  {
410
 
    uint32 add_length= arg_length / cs->mbminlen * str_charset->mbmaxlen;
 
410
    uint32_t add_length= arg_length / cs->mbminlen * str_charset->mbmaxlen;
411
411
    uint dummy_errors;
412
412
    if (realloc(str_length + add_length)) 
413
413
      return true;
425
425
}
426
426
 
427
427
 
428
 
bool String::append(IO_CACHE* file, uint32 arg_length)
 
428
bool String::append(IO_CACHE* file, uint32_t arg_length)
429
429
{
430
430
  if (realloc(str_length+arg_length))
431
431
    return true;
438
438
  return false;
439
439
}
440
440
 
441
 
bool String::append_with_prefill(const char *s,uint32 arg_length,
442
 
                 uint32 full_length, char fill_char)
 
441
bool String::append_with_prefill(const char *s,uint32_t arg_length,
 
442
                 uint32_t full_length, char fill_char)
443
443
{
444
444
  int t_length= arg_length > full_length ? arg_length : full_length;
445
445
 
455
455
  return false;
456
456
}
457
457
 
458
 
uint32 String::numchars()
 
458
uint32_t String::numchars()
459
459
{
460
460
  return str_charset->cset->numchars(str_charset, Ptr, Ptr+str_length);
461
461
}
462
462
 
463
 
int String::charpos(int i,uint32 offset)
 
463
int String::charpos(int i,uint32_t offset)
464
464
{
465
465
  if (i <= 0)
466
466
    return i;
467
467
  return str_charset->cset->charpos(str_charset,Ptr+offset,Ptr+str_length,i);
468
468
}
469
469
 
470
 
int String::strstr(const String &s,uint32 offset)
 
470
int String::strstr(const String &s,uint32_t offset)
471
471
{
472
472
  if (s.length()+offset <= str_length)
473
473
  {
498
498
** Search string from end. Offset is offset to the end of string
499
499
*/
500
500
 
501
 
int String::strrstr(const String &s,uint32 offset)
 
501
int String::strrstr(const String &s,uint32_t offset)
502
502
{
503
503
  if (s.length() <= offset && offset <= str_length)
504
504
  {
530
530
  If wrong parameter or not enough memory, do nothing
531
531
*/
532
532
 
533
 
bool String::replace(uint32 offset,uint32 arg_length,const String &to)
 
533
bool String::replace(uint32_t offset,uint32_t arg_length,const String &to)
534
534
{
535
535
  return replace(offset,arg_length,to.ptr(),to.length());
536
536
}
537
537
 
538
 
bool String::replace(uint32 offset,uint32 arg_length,
539
 
                     const char *to, uint32 to_length)
 
538
bool String::replace(uint32_t offset,uint32_t arg_length,
 
539
                     const char *to, uint32_t to_length)
540
540
{
541
541
  long diff = (long) to_length-(long) arg_length;
542
542
  if (offset+arg_length <= str_length)
552
552
    {
553
553
      if (diff)
554
554
      {
555
 
        if (realloc(str_length+(uint32) diff))
 
555
        if (realloc(str_length+(uint32_t) diff))
556
556
          return true;
557
557
        bmove_upp((uchar*) Ptr+str_length+diff, (uchar*) Ptr+str_length,
558
558
                  str_length-offset-arg_length);
560
560
      if (to_length)
561
561
        memcpy(Ptr+offset,to,to_length);
562
562
    }
563
 
    str_length+=(uint32) diff;
 
563
    str_length+=(uint32_t) diff;
564
564
  }
565
565
  return false;
566
566
}
567
567
 
568
568
 
569
569
// added by Holyfoot for "geometry" needs
570
 
int String::reserve(uint32 space_needed, uint32 grow_by)
 
570
int String::reserve(uint32_t space_needed, uint32_t grow_by)
571
571
{
572
572
  if (Alloced_length < str_length + space_needed)
573
573
  {
577
577
  return false;
578
578
}
579
579
 
580
 
void String::qs_append(const char *str, uint32 len)
 
580
void String::qs_append(const char *str, uint32_t len)
581
581
{
582
582
  memcpy(Ptr + str_length, str, len + 1);
583
583
  str_length += len;
657
657
 
658
658
int stringcmp(const String *s,const String *t)
659
659
{
660
 
  uint32 s_len=s->length(),t_len=t->length(),len=min(s_len,t_len);
 
660
  uint32_t s_len=s->length(),t_len=t->length(),len=min(s_len,t_len);
661
661
  int cmp= memcmp(s->ptr(), t->ptr(), len);
662
662
  return (cmp) ? cmp : (int) (s_len - t_len);
663
663
}
664
664
 
665
665
 
666
 
String *copy_if_not_alloced(String *to,String *from,uint32 from_length)
 
666
String *copy_if_not_alloced(String *to,String *from,uint32_t from_length)
667
667
{
668
668
  if (from->Alloced_length >= from_length)
669
669
    return from;
704
704
*/
705
705
 
706
706
 
707
 
static uint32
708
 
copy_and_convert_extended(char *to, uint32 to_length, CHARSET_INFO *to_cs, 
709
 
                          const char *from, uint32 from_length,
 
707
static uint32_t
 
708
copy_and_convert_extended(char *to, uint32_t to_length, CHARSET_INFO *to_cs, 
 
709
                          const char *from, uint32_t from_length,
710
710
                          CHARSET_INFO *from_cs,
711
711
                          uint *errors)
712
712
{
756
756
      break;
757
757
  }
758
758
  *errors= error_count;
759
 
  return (uint32) (to - to_start);
 
759
  return (uint32_t) (to - to_start);
760
760
}
761
761
 
762
762
 
763
763
/*
764
764
  Optimized for quick copying of ASCII characters in the range 0x00..0x7F.
765
765
*/
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,
 
766
uint32_t
 
767
copy_and_convert(char *to, uint32_t to_length, CHARSET_INFO *to_cs, 
 
768
                 const char *from, uint32_t from_length, CHARSET_INFO *from_cs,
769
769
                 uint *errors)
770
770
{
771
771
  /*
776
776
    return copy_and_convert_extended(to, to_length, to_cs,
777
777
                                     from, from_length, from_cs, errors);
778
778
 
779
 
  uint32 length= min(to_length, from_length), length2= length;
 
779
  uint32_t length= min(to_length, from_length), length2= length;
780
780
 
781
781
#if defined(__i386__)
782
782
  /*
788
788
  */
789
789
  for ( ; length >= 4; length-= 4, from+= 4, to+= 4)
790
790
  {
791
 
    if ((*(uint32*)from) & 0x80808080)
 
791
    if ((*(uint32_t*)from) & 0x80808080)
792
792
      break;
793
 
    *((uint32*) to)= *((const uint32*) from);
 
793
    *((uint32_t*) to)= *((const uint32_t*) from);
794
794
  }
795
795
#endif
796
796
 
803
803
    }
804
804
    if (*((unsigned char*) from) > 0x7F) /* A non-ASCII character */
805
805
    {
806
 
      uint32 copied_length= length2 - length;
 
806
      uint32_t copied_length= length2 - length;
807
807
      to_length-= copied_length;
808
808
      from_length-= copied_length;
809
809
      return copied_length + copy_and_convert_extended(to, to_length,
908
908
*/
909
909
 
910
910
 
911
 
uint32
 
911
uint32_t
912
912
well_formed_copy_nchars(CHARSET_INFO *to_cs,
913
913
                        char *to, uint to_length,
914
914
                        CHARSET_INFO *from_cs,
1032
1032
    *from_end_pos= from;
1033
1033
    res= to - to_start;
1034
1034
  }
1035
 
  return (uint32) res;
 
1035
  return (uint32_t) res;
1036
1036
}
1037
1037
 
1038
1038
 
1084
1084
void String::swap(String &s)
1085
1085
{
1086
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);
 
1087
  swap_variables(uint32_t, str_length, s.str_length);
 
1088
  swap_variables(uint32_t, Alloced_length, s.Alloced_length);
1089
1089
  swap_variables(bool, alloced, s.alloced);
1090
1090
  swap_variables(CHARSET_INFO*, str_charset, s.str_charset);
1091
1091
}