~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/sql_string.h

  • 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:
25
25
 
26
26
class String;
27
27
int sortcmp(const String *a,const String *b, CHARSET_INFO *cs);
28
 
String *copy_if_not_alloced(String *a,String *b,uint32 arg_length);
29
 
uint32 copy_and_convert(char *to, uint32 to_length, CHARSET_INFO *to_cs,
30
 
                        const char *from, uint32 from_length,
 
28
String *copy_if_not_alloced(String *a,String *b,uint32_t arg_length);
 
29
uint32_t copy_and_convert(char *to, uint32_t to_length, CHARSET_INFO *to_cs,
 
30
                        const char *from, uint32_t from_length,
31
31
                        CHARSET_INFO *from_cs, uint *errors);
32
 
uint32 well_formed_copy_nchars(CHARSET_INFO *to_cs,
 
32
uint32_t well_formed_copy_nchars(CHARSET_INFO *to_cs,
33
33
                               char *to, uint to_length,
34
34
                               CHARSET_INFO *from_cs,
35
35
                               const char *from, uint from_length,
44
44
class String
45
45
{
46
46
  char *Ptr;
47
 
  uint32 str_length,Alloced_length;
 
47
  uint32_t str_length,Alloced_length;
48
48
  bool alloced;
49
49
  CHARSET_INFO *str_charset;
50
50
public:
53
53
    Ptr=0; str_length=Alloced_length=0; alloced=0; 
54
54
    str_charset= &my_charset_bin; 
55
55
  }
56
 
  String(uint32 length_arg)
 
56
  String(uint32_t length_arg)
57
57
  { 
58
58
    alloced=0; Alloced_length=0; (void) real_alloc(length_arg); 
59
59
    str_charset= &my_charset_bin;
63
63
    Ptr=(char*) str; str_length=(uint) strlen(str); Alloced_length=0; alloced=0;
64
64
    str_charset=cs;
65
65
  }
66
 
  String(const char *str,uint32 len, CHARSET_INFO *cs)
 
66
  String(const char *str,uint32_t len, CHARSET_INFO *cs)
67
67
  { 
68
68
    Ptr=(char*) str; str_length=len; Alloced_length=0; alloced=0;
69
69
    str_charset=cs;
70
70
  }
71
 
  String(char *str,uint32 len, CHARSET_INFO *cs)
 
71
  String(char *str,uint32_t len, CHARSET_INFO *cs)
72
72
  { 
73
73
    Ptr=(char*) str; Alloced_length=str_length=len; alloced=0;
74
74
    str_charset=cs;
92
92
  inline void set_charset(CHARSET_INFO *charset_arg)
93
93
  { str_charset= charset_arg; }
94
94
  inline CHARSET_INFO *charset() const { return str_charset; }
95
 
  inline uint32 length() const { return str_length;}
96
 
  inline uint32 alloced_length() const { return Alloced_length;}
97
 
  inline char& operator [] (uint32 i) const { return Ptr[i]; }
98
 
  inline void length(uint32 len) { str_length=len ; }
 
95
  inline uint32_t length() const { return str_length;}
 
96
  inline uint32_t alloced_length() const { return Alloced_length;}
 
97
  inline char& operator [] (uint32_t i) const { return Ptr[i]; }
 
98
  inline void length(uint32_t len) { str_length=len ; }
99
99
  inline bool is_empty() { return (str_length == 0); }
100
100
  inline void mark_as_const() { Alloced_length= 0;}
101
101
  inline const char *ptr() const { return Ptr; }
120
120
    return Ptr;
121
121
  }
122
122
 
123
 
  void set(String &str,uint32 offset,uint32 arg_length)
 
123
  void set(String &str,uint32_t offset,uint32_t arg_length)
124
124
  {
125
125
    assert(&str != this);
126
126
    free();
131
131
      Alloced_length=0;
132
132
    str_charset=str.str_charset;
133
133
  }
134
 
  inline void set(char *str,uint32 arg_length, CHARSET_INFO *cs)
 
134
  inline void set(char *str,uint32_t arg_length, CHARSET_INFO *cs)
135
135
  {
136
136
    free();
137
137
    Ptr=(char*) str; str_length=Alloced_length=arg_length ; alloced=0;
138
138
    str_charset=cs;
139
139
  }
140
 
  inline void set(const char *str,uint32 arg_length, CHARSET_INFO *cs)
 
140
  inline void set(const char *str,uint32_t arg_length, CHARSET_INFO *cs)
141
141
  {
142
142
    free();
143
143
    Ptr=(char*) str; str_length=arg_length; Alloced_length=0 ; alloced=0;
144
144
    str_charset=cs;
145
145
  }
146
 
  bool set_ascii(const char *str, uint32 arg_length);
147
 
  inline void set_quick(char *str,uint32 arg_length, CHARSET_INFO *cs)
 
146
  bool set_ascii(const char *str, uint32_t arg_length);
 
147
  inline void set_quick(char *str,uint32_t arg_length, CHARSET_INFO *cs)
148
148
  {
149
149
    if (!alloced)
150
150
    {
197
197
      str_length=0;                             /* Safety */
198
198
    }
199
199
  }
200
 
  inline bool alloc(uint32 arg_length)
 
200
  inline bool alloc(uint32_t arg_length)
201
201
  {
202
202
    if (arg_length < Alloced_length)
203
203
      return 0;
204
204
    return real_alloc(arg_length);
205
205
  }
206
 
  bool real_alloc(uint32 arg_length);                   // Empties old string
207
 
  bool realloc(uint32 arg_length);
208
 
  inline void shrink(uint32 arg_length)         // Shrink buffer
 
206
  bool real_alloc(uint32_t arg_length);                 // Empties old string
 
207
  bool realloc(uint32_t arg_length);
 
208
  inline void shrink(uint32_t arg_length)               // Shrink buffer
209
209
  {
210
210
    if (arg_length < Alloced_length)
211
211
    {
241
241
 
242
242
  bool copy();                                  // Alloc string if not alloced
243
243
  bool copy(const String &s);                   // Allocate new string
244
 
  bool copy(const char *s,uint32 arg_length, CHARSET_INFO *cs); // Allocate new string
245
 
  static bool needs_conversion(uint32 arg_length,
 
244
  bool copy(const char *s,uint32_t arg_length, CHARSET_INFO *cs);       // Allocate new string
 
245
  static bool needs_conversion(uint32_t arg_length,
246
246
                               CHARSET_INFO *cs_from, CHARSET_INFO *cs_to,
247
 
                               uint32 *offset);
248
 
  bool copy_aligned(const char *s, uint32 arg_length, uint32 offset,
 
247
                               uint32_t *offset);
 
248
  bool copy_aligned(const char *s, uint32_t arg_length, uint32_t offset,
249
249
                    CHARSET_INFO *cs);
250
 
  bool set_or_copy_aligned(const char *s, uint32 arg_length, CHARSET_INFO *cs);
251
 
  bool copy(const char*s,uint32 arg_length, CHARSET_INFO *csfrom,
 
250
  bool set_or_copy_aligned(const char *s, uint32_t arg_length, CHARSET_INFO *cs);
 
251
  bool copy(const char*s,uint32_t arg_length, CHARSET_INFO *csfrom,
252
252
            CHARSET_INFO *csto, uint *errors);
253
253
  bool append(const String &s);
254
254
  bool append(const char *s);
255
 
  bool append(const char *s,uint32 arg_length);
256
 
  bool append(const char *s,uint32 arg_length, CHARSET_INFO *cs);
257
 
  bool append(IO_CACHE* file, uint32 arg_length);
258
 
  bool append_with_prefill(const char *s, uint32 arg_length, 
259
 
                           uint32 full_length, char fill_char);
260
 
  int strstr(const String &search,uint32 offset=0); // Returns offset to substring or -1
261
 
  int strrstr(const String &search,uint32 offset=0); // Returns offset to substring or -1
262
 
  bool replace(uint32 offset,uint32 arg_length,const char *to,uint32 length);
263
 
  bool replace(uint32 offset,uint32 arg_length,const String &to);
 
255
  bool append(const char *s,uint32_t arg_length);
 
256
  bool append(const char *s,uint32_t arg_length, CHARSET_INFO *cs);
 
257
  bool append(IO_CACHE* file, uint32_t arg_length);
 
258
  bool append_with_prefill(const char *s, uint32_t arg_length, 
 
259
                           uint32_t full_length, char fill_char);
 
260
  int strstr(const String &search,uint32_t offset=0); // Returns offset to substring or -1
 
261
  int strrstr(const String &search,uint32_t offset=0); // Returns offset to substring or -1
 
262
  bool replace(uint32_t offset,uint32_t arg_length,const char *to,uint32_t length);
 
263
  bool replace(uint32_t offset,uint32_t arg_length,const String &to);
264
264
  inline bool append(char chr)
265
265
  {
266
266
    if (str_length < Alloced_length)
275
275
    }
276
276
    return 0;
277
277
  }
278
 
  bool fill(uint32 max_length,char fill);
 
278
  bool fill(uint32_t max_length,char fill);
279
279
  void strip_sp();
280
280
  friend int sortcmp(const String *a,const String *b, CHARSET_INFO *cs);
281
281
  friend int stringcmp(const String *a,const String *b);
282
 
  friend String *copy_if_not_alloced(String *a,String *b,uint32 arg_length);
283
 
  uint32 numchars();
284
 
  int charpos(int i,uint32 offset=0);
 
282
  friend String *copy_if_not_alloced(String *a,String *b,uint32_t arg_length);
 
283
  uint32_t numchars();
 
284
  int charpos(int i,uint32_t offset=0);
285
285
 
286
 
  int reserve(uint32 space_needed)
 
286
  int reserve(uint32_t space_needed)
287
287
  {
288
288
    return realloc(str_length + space_needed);
289
289
  }
290
 
  int reserve(uint32 space_needed, uint32 grow_by);
 
290
  int reserve(uint32_t space_needed, uint32_t grow_by);
291
291
 
292
292
  /*
293
293
    The following append operations do NOT check alloced memory
298
298
  {
299
299
    Ptr[str_length++] = c;
300
300
  }
301
 
  void q_append(const uint32 n)
 
301
  void q_append(const uint32_t n)
302
302
  {
303
303
    int4store(Ptr + str_length, n);
304
304
    str_length += 4;
313
313
    float8store(Ptr + str_length, *d);
314
314
    str_length += 8;
315
315
  }
316
 
  void q_append(const char *data, uint32 data_len)
 
316
  void q_append(const char *data, uint32_t data_len)
317
317
  {
318
318
    memcpy(Ptr + str_length, data, data_len);
319
319
    str_length += data_len;
320
320
  }
321
321
 
322
 
  void write_at_position(int position, uint32 value)
 
322
  void write_at_position(int position, uint32_t value)
323
323
  {
324
324
    int4store(Ptr + position,value);
325
325
  }
326
326
 
327
 
  void qs_append(const char *str, uint32 len);
 
327
  void qs_append(const char *str, uint32_t len);
328
328
  void qs_append(double d);
329
329
  void qs_append(double *d);
330
330
  inline void qs_append(const char c)
337
337
 
338
338
  /* Inline (general) functions used by the protocol functions */
339
339
 
340
 
  inline char *prep_append(uint32 arg_length, uint32 step_alloc)
 
340
  inline char *prep_append(uint32_t arg_length, uint32_t step_alloc)
341
341
  {
342
 
    uint32 new_length= arg_length + str_length;
 
342
    uint32_t new_length= arg_length + str_length;
343
343
    if (new_length > Alloced_length)
344
344
    {
345
345
      if (realloc(new_length + step_alloc))
346
346
        return 0;
347
347
    }
348
 
    uint32 old_length= str_length;
 
348
    uint32_t old_length= str_length;
349
349
    str_length+= arg_length;
350
350
    return Ptr+ old_length;                     /* Area to use */
351
351
  }
352
352
 
353
 
  inline bool append(const char *s, uint32 arg_length, uint32 step_alloc)
 
353
  inline bool append(const char *s, uint32_t arg_length, uint32_t step_alloc)
354
354
  {
355
 
    uint32 new_length= arg_length + str_length;
 
355
    uint32_t new_length= arg_length + str_length;
356
356
    if (new_length > Alloced_length && realloc(new_length + step_alloc))
357
357
      return true;
358
358
    memcpy(Ptr+str_length, s, arg_length);