48
48
int sortcmp(const String *a,const String *b, const CHARSET_INFO * const cs);
49
49
int stringcmp(const String *a,const String *b);
50
String *copy_if_not_alloced(String *a,String *b,uint32_t arg_length);
51
uint32_t well_formed_copy_nchars(const CHARSET_INFO * const to_cs,
52
char *to, uint32_t to_length,
50
String *copy_if_not_alloced(String *a,String *b,size_t arg_length);
51
size_t well_formed_copy_nchars(const CHARSET_INFO * const to_cs,
52
char *to, size_t to_length,
53
53
const CHARSET_INFO * const from_cs,
54
const char *from, uint32_t from_length,
54
const char *from, size_t from_length,
56
56
const char **well_formed_error_pos,
57
57
const char **cannot_convert_error_pos,
58
58
const char **from_end_pos);
64
uint32_t str_length,Alloced_length;
64
size_t str_length,Alloced_length;
66
66
const CHARSET_INFO *str_charset;
70
String(uint32_t length_arg);
70
String(size_t length_arg);
71
71
String(const char *str, const CHARSET_INFO * const cs);
72
String(const char *str, uint32_t len, const CHARSET_INFO * const cs);
73
String(char *str, uint32_t len, const CHARSET_INFO * const cs);
72
String(const char *str, size_t len, const CHARSET_INFO * const cs);
73
String(char *str, size_t len, const CHARSET_INFO * const cs);
74
74
String(const String &str);
76
76
static void *operator new(size_t size, memory::Root *mem_root);
83
83
inline void set_charset(const CHARSET_INFO * const charset_arg)
84
84
{ str_charset= charset_arg; }
85
85
inline const CHARSET_INFO *charset() const { return str_charset; }
86
inline uint32_t length() const { return str_length;}
87
inline uint32_t alloced_length() const { return Alloced_length;}
88
inline char& operator [] (uint32_t i) const { return Ptr[i]; }
89
inline void length(uint32_t len) { str_length=len ; }
86
inline size_t length() const { return str_length;}
87
inline size_t alloced_length() const { return Alloced_length;}
88
inline char& operator [] (size_t i) const { return Ptr[i]; }
89
inline void length(size_t len) { str_length=len ; }
90
90
inline bool is_empty() { return (str_length == 0); }
91
91
inline void mark_as_const() { Alloced_length= 0;}
92
92
inline char *ptr() { return Ptr; }
135
135
Alloced_length=0;
136
136
str_charset=str.str_charset;
138
inline void set(char *str,uint32_t arg_length, const CHARSET_INFO * const cs)
138
inline void set(char *str,size_t arg_length, const CHARSET_INFO * const cs)
141
141
Ptr= str; str_length=Alloced_length=arg_length ; alloced=0;
144
inline void set(const char *str,uint32_t arg_length, const CHARSET_INFO * const cs)
144
inline void set(const char *str,size_t arg_length, const CHARSET_INFO * const cs)
147
147
Ptr= const_cast<char*>(str);
148
148
str_length=arg_length; Alloced_length=0 ; alloced=0;
151
bool set_ascii(const char *str, uint32_t arg_length);
152
inline void set_quick(char *str,uint32_t arg_length, const CHARSET_INFO * const cs)
151
bool set_ascii(const char *str, size_t arg_length);
152
inline void set_quick(char *str,size_t arg_length, const CHARSET_INFO * const cs)
162
162
{ return set_int(num, false, cs); }
163
163
bool set(uint64_t num, const CHARSET_INFO * const cs)
164
164
{ return set_int(static_cast<int64_t>(num), true, cs); }
165
bool set_real(double num,uint32_t decimals, const CHARSET_INFO * const cs);
165
bool set_real(double num,size_t decimals, const CHARSET_INFO * const cs);
202
202
str_length=0; /* Safety */
205
inline bool alloc(uint32_t arg_length)
205
inline bool alloc(size_t arg_length)
207
207
if (arg_length < Alloced_length)
209
209
return real_alloc(arg_length);
211
bool real_alloc(uint32_t arg_length); // Empties old string
212
bool realloc(uint32_t arg_length);
213
inline void shrink(uint32_t arg_length) // Shrink buffer
211
bool real_alloc(size_t arg_length); // Empties old string
212
bool realloc(size_t arg_length);
213
inline void shrink(size_t arg_length) // Shrink buffer
215
215
if (arg_length < Alloced_length)
247
247
bool copy(); // Alloc string if not alloced
248
248
bool copy(const String &s); // Allocate new string
249
bool copy(const char *s,uint32_t arg_length, const CHARSET_INFO * const cs); // Allocate new string
250
static bool needs_conversion(uint32_t arg_length,
249
bool copy(const char *s,size_t arg_length, const CHARSET_INFO * const cs); // Allocate new string
250
static bool needs_conversion(size_t arg_length,
251
251
const CHARSET_INFO * const cs_from, const CHARSET_INFO * const cs_to,
253
bool set_or_copy_aligned(const char *s, uint32_t arg_length, const CHARSET_INFO * const cs);
254
bool copy(const char*s,uint32_t arg_length, const CHARSET_INFO * const csfrom,
255
const CHARSET_INFO * const csto, uint32_t *errors);
253
bool set_or_copy_aligned(const char *s, size_t arg_length, const CHARSET_INFO * const cs);
254
bool copy(const char*s,size_t arg_length, const CHARSET_INFO * const csfrom,
255
const CHARSET_INFO * const csto, size_t *errors);
256
256
bool append(const String &s);
257
257
bool append(const char *s);
258
bool append(const char *s,uint32_t arg_length);
259
bool append(const char *s,uint32_t arg_length, const CHARSET_INFO * const cs);
260
bool append_with_prefill(const char *s, uint32_t arg_length,
261
uint32_t full_length, char fill_char);
262
int strstr(const String &search,uint32_t offset=0); // Returns offset to substring or -1
263
int strrstr(const String &search,uint32_t offset=0); // Returns offset to substring or -1
264
bool replace(uint32_t offset,uint32_t arg_length,const char *to,uint32_t length);
265
bool replace(uint32_t offset,uint32_t arg_length,const String &to);
258
bool append(const char *s,size_t arg_length);
259
bool append(const char *s,size_t arg_length, const CHARSET_INFO * const cs);
260
bool append_with_prefill(const char *s, size_t arg_length,
261
size_t full_length, char fill_char);
262
int strstr(const String &search,size_t offset=0); // Returns offset to substring or -1
263
int strrstr(const String &search,size_t offset=0); // Returns offset to substring or -1
264
bool replace(size_t offset,size_t arg_length,const char *to,size_t length);
265
bool replace(size_t offset,size_t arg_length,const String &to);
266
266
inline bool append(char chr)
268
268
if (str_length < Alloced_length)
280
280
friend int sortcmp(const String *a,const String *b, const CHARSET_INFO * const cs);
281
281
friend int stringcmp(const String *a,const String *b);
282
friend String *copy_if_not_alloced(String *a,String *b,uint32_t arg_length);
284
int charpos(int i,uint32_t offset=0);
282
friend String *copy_if_not_alloced(String *a,String *b,size_t arg_length);
284
int charpos(int i,size_t offset=0);
286
int reserve(uint32_t space_needed)
286
int reserve(size_t space_needed)
288
288
return realloc(str_length + space_needed);
290
int reserve(uint32_t space_needed, uint32_t grow_by);
290
int reserve(size_t space_needed, size_t grow_by);
293
293
The following append operations do NOT check alloced memory
295
295
qs_*** methods writes string representation of value
297
297
void q_append(const char c);
298
void q_append(const uint32_t n);
298
void q_append(const size_t n);
299
299
void q_append(double d);
300
300
void q_append(double *d);
301
void q_append(const char *data, uint32_t data_len);
302
void write_at_position(int position, uint32_t value);
301
void q_append(const char *data, size_t data_len);
302
void write_at_position(int position, size_t value);
304
304
/* Inline (general) functions used by the protocol functions */
306
inline char *prep_append(uint32_t arg_length, uint32_t step_alloc)
306
inline char *prep_append(size_t arg_length, size_t step_alloc)
308
uint32_t new_length= arg_length + str_length;
308
size_t new_length= arg_length + str_length;
309
309
if (new_length > Alloced_length)
311
311
if (realloc(new_length + step_alloc))
314
uint32_t old_length= str_length;
314
size_t old_length= str_length;
315
315
str_length+= arg_length;
316
316
return Ptr+ old_length; /* Area to use */
319
inline bool append(const char *s, uint32_t arg_length, uint32_t step_alloc)
319
inline bool append(const char *s, size_t arg_length, size_t step_alloc)
321
uint32_t new_length= arg_length + str_length;
321
size_t new_length= arg_length + str_length;
322
322
if (new_length > Alloced_length && realloc(new_length + step_alloc))
324
324
memcpy(Ptr+str_length, s, arg_length);