195
Copy a multi-byte character sets with adding leading zeros.
201
arg_length Length of string. This should NOT be dividable with
203
offset arg_length % cs->mb_minlength
204
cs Character set for 'str'
207
For real multi-byte, ascii incompatible charactser sets,
208
like UCS-2, add leading zeros if we have an incomplete character.
211
will automatically be converted into
219
bool String::copy_aligned(const char *str,uint32_t arg_length, uint32_t offset,
220
const CHARSET_INFO * const cs)
222
/* How many bytes are in incomplete character */
223
offset= cs->mbmaxlen - offset; /* How many zeros we should prepend */
224
assert(offset && offset != cs->mbmaxlen);
226
uint32_t aligned_length= arg_length + offset;
227
if (alloc(aligned_length))
231
Note, this is only safe for big-endian UCS-2.
232
If we add little-endian UCS-2 sometimes, this code
233
will be more complicated. But it's OK for now.
235
memset(Ptr, 0, offset);
236
memcpy(Ptr + offset, str, arg_length);
237
Ptr[aligned_length]=0;
238
/* str_length is always >= 0 as arg_length is != 0 */
239
str_length= aligned_length;
245
196
bool String::set_or_copy_aligned(const char *str,uint32_t arg_length,
246
197
const CHARSET_INFO * const cs)
248
199
/* How many bytes are in incomplete character */
249
uint32_t offset= (arg_length % cs->mbminlen);
251
if (!offset) /* All characters are complete, just copy */
253
set(str, arg_length, cs);
256
return copy_aligned(str, arg_length, offset, cs);
200
uint32_t offset= (arg_length % cs->mbminlen);
202
assert(!offset); /* All characters are complete, just copy */
204
set(str, arg_length, cs);
259
208
/* Copy with charset conversion */
261
210
bool String::copy(const char *str, uint32_t arg_length,
262
const CHARSET_INFO * const from_cs,
211
const CHARSET_INFO * const,
263
212
const CHARSET_INFO * const to_cs, uint32_t *errors)
266
if (!needs_conversion(arg_length, from_cs, to_cs, &offset))
269
return copy(str, arg_length, to_cs);
271
if ((from_cs == &my_charset_bin) && offset)
274
return copy_aligned(str, arg_length, offset, to_cs);
276
uint32_t new_length= to_cs->mbmaxlen*arg_length;
277
if (alloc(new_length))
279
str_length=copy_and_convert((char*) Ptr, new_length, to_cs,
280
str, arg_length, from_cs, errors);
215
return copy(str, arg_length, to_cs);
287
220
Set a string to the value of a latin1-string, keeping the original charset
291
224
str String of a simple charset (latin1)
313
246
return copy(str, arg_length, &my_charset_utf8_general_ci, str_charset, &dummy_errors);
317
/* This is used by mysql.cc */
319
bool String::fill(uint32_t max_length,char fill_char)
321
if (str_length > max_length)
322
Ptr[str_length=max_length]=0;
325
if (realloc(max_length))
327
memset(Ptr+str_length, fill_char, max_length-str_length);
328
str_length=max_length;
333
249
bool String::append(const String &s)
393
309
with character set recoding
396
bool String::append(const char *s,uint32_t arg_length, const CHARSET_INFO * const cs)
398
uint32_t dummy_offset;
400
if (needs_conversion(arg_length, cs, str_charset, &dummy_offset))
402
uint32_t add_length= arg_length / cs->mbminlen * str_charset->mbmaxlen;
403
uint32_t dummy_errors;
404
if (realloc(str_length + add_length))
406
str_length+= copy_and_convert(Ptr+str_length, add_length, str_charset,
407
s, arg_length, cs, &dummy_errors);
411
if (realloc(str_length + arg_length))
413
memcpy(Ptr + str_length, s, arg_length);
414
str_length+= arg_length;
420
bool String::append(IO_CACHE* file, uint32_t arg_length)
422
if (realloc(str_length+arg_length))
424
if (my_b_read(file, (unsigned char*) Ptr + str_length, arg_length))
429
str_length+=arg_length;
312
bool String::append(const char *s,uint32_t arg_length, const CHARSET_INFO * const)
314
if (realloc(str_length + arg_length))
316
memcpy(Ptr + str_length, s, arg_length);
317
str_length+= arg_length;
433
323
bool String::append_with_prefill(const char *s,uint32_t arg_length,
434
324
uint32_t full_length, char fill_char)
561
// added by Holyfoot for "geometry" needs
562
int String::reserve(uint32_t space_needed, uint32_t grow_by)
564
if (Alloced_length < str_length + space_needed)
566
if (realloc(Alloced_length + cmax(space_needed, grow_by) - 1))
572
void String::qs_append(const char *str, uint32_t len)
574
memcpy(Ptr + str_length, str, len + 1);
578
void String::qs_append(double d)
580
char *buff = Ptr + str_length;
581
str_length+= my_gcvt(d, MY_GCVT_ARG_DOUBLE, FLOATING_POINT_BUFFER - 1, buff, NULL);
584
void String::qs_append(double *d)
587
float8get(ld, (char*) d);
591
void String::qs_append(int i)
593
char *buff= Ptr + str_length;
594
char *end= int10_to_str(i, buff, -10);
595
str_length+= (int) (end-buff);
598
void String::qs_append(uint32_t i)
600
char *buff= Ptr + str_length;
601
char *end= int10_to_str(i, buff, 10);
602
str_length+= (int) (end-buff);
606
453
Compare strings according to collation, without end space.
820
668
are read from "src". Any sequences of bytes representing
821
669
a not-well-formed substring (according to cs) are hex-encoded,
822
670
and all well-formed substrings (according to cs) are copied as is.
823
Not more than "dstlen" bytes are written to "dst". The number
671
Not more than "dstlen" bytes are written to "dst". The number
824
672
of bytes written to "dst" is returned.
826
674
@param cs character set pointer of the destination string
827
675
@param[out] dst destination string
828
676
@param dstlen size of dst
1043
str->append(STRING_WITH_LEN("\\\\"));
891
str->append("\\\\", sizeof("\\\\")-1);
1046
str->append(STRING_WITH_LEN("\\0"));
894
str->append("\\0", sizeof("\\0")-1);
1049
str->append(STRING_WITH_LEN("\\'"));
897
str->append("\\'", sizeof("\\'")-1);
1052
str->append(STRING_WITH_LEN("\\n"));
900
str->append("\\n", sizeof("\\n")-1);
1055
str->append(STRING_WITH_LEN("\\r"));
903
str->append("\\r", sizeof("\\r")-1);
1057
905
case '\032': // Ctrl-Z
1058
str->append(STRING_WITH_LEN("\\Z"));
906
str->append("\\Z", sizeof("\\Z")-1);
915
Quote the given identifier.
916
If the given identifier is empty, it will be quoted.
920
name the identifier to be appended
921
name_length length of the appending identifier
924
/* Factor the extern out */
925
extern const CHARSET_INFO *system_charset_info, *files_charset_info;
927
void String::append_identifier(const char *name, uint32_t in_length)
929
const char *name_end;
934
The identifier must be quoted as it includes a quote character or
938
reserve(in_length*2 + 2);
939
quote_char= (char) q;
940
append("e_char, 1, system_charset_info);
942
for (name_end= name+in_length ; name < name_end ; name+= in_length)
944
unsigned char chr= (unsigned char) *name;
945
in_length= my_mbcharlen(system_charset_info, chr);
947
my_mbcharlen can return 0 on a wrong multibyte
948
sequence. It is possible when upgrading from 4.0,
949
and identifier contains some accented characters.
950
The manual says it does not work. So we'll just
951
change length to 1 not to hang in the endless loop.
955
if (in_length == 1 && chr == (unsigned char) quote_char)
956
append("e_char, 1, system_charset_info);
957
append(name, in_length, system_charset_info);
959
append("e_char, 1, system_charset_info);
1068
964
Exchange state of this object and argument.