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,
248
199
/* How many bytes are in incomplete character */
249
200
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);
202
assert(!offset); /* All characters are complete, just copy */
204
set(str, arg_length, cs);
259
208
/* Copy with charset conversion */
271
220
if ((from_cs == &my_charset_bin) && offset)
274
return copy_aligned(str, arg_length, offset, to_cs);
223
assert((from_cs == &my_charset_bin) && offset);
224
return false; //copy_aligned(str, arg_length, offset, to_cs);
276
226
uint32_t new_length= to_cs->mbmaxlen*arg_length;
277
227
if (alloc(new_length))
313
263
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
266
bool String::append(const String &s)