~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_string.cc

  • Committer: Brian Aker
  • Date: 2009-03-05 07:55:26 UTC
  • mfrom: (910.1.5 drizzle)
  • Revision ID: brian@tangent.org-20090305075526-ua34bjproq6oxujx
Merge of Brian (test extensions, dead code killing)

Show diffs side-by-side

added added

removed removed

Lines of Context:
191
191
}
192
192
 
193
193
 
194
 
/*
195
 
  Copy a multi-byte character sets with adding leading zeros.
196
 
 
197
 
  SYNOPSIS
198
 
 
199
 
  copy_aligned()
200
 
  str                   String to copy
201
 
  arg_length            Length of string. This should NOT be dividable with
202
 
                        cs->mbminlen.
203
 
  offset                arg_length % cs->mb_minlength
204
 
  cs                    Character set for 'str'
205
 
 
206
 
  NOTES
207
 
    For real multi-byte, ascii incompatible charactser sets,
208
 
    like UCS-2, add leading zeros if we have an incomplete character.
209
 
    Thus,
210
 
      SELECT _ucs2 0xAA
211
 
    will automatically be converted into
212
 
      SELECT _ucs2 0x00AA
213
 
 
214
 
  RETURN
215
 
    0  ok
216
 
    1  error
217
 
*/
218
 
 
219
 
bool String::copy_aligned(const char *str,uint32_t arg_length, uint32_t offset,
220
 
                          const CHARSET_INFO * const cs)
221
 
{
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);
225
 
 
226
 
  uint32_t aligned_length= arg_length + offset;
227
 
  if (alloc(aligned_length))
228
 
    return true;
229
 
 
230
 
  /*
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.
234
 
  */
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;
240
 
  str_charset= cs;
241
 
  return false;
242
 
}
243
194
 
244
195
 
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);
250
201
 
251
 
  if (!offset) /* All characters are complete, just copy */
252
 
  {
253
 
    set(str, arg_length, cs);
254
 
    return false;
255
 
  }
256
 
  return copy_aligned(str, arg_length, offset, cs);
 
202
  assert(!offset); /* All characters are complete, just copy */
 
203
 
 
204
  set(str, arg_length, cs);
 
205
  return false;
257
206
}
258
207
 
259
208
        /* Copy with charset conversion */
271
220
  if ((from_cs == &my_charset_bin) && offset)
272
221
  {
273
222
    *errors= 0;
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);
275
225
  }
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);
314
264
}
315
265
 
316
 
 
317
 
/* This is used by mysql.cc */
318
 
 
319
 
bool String::fill(uint32_t max_length,char fill_char)
320
 
{
321
 
  if (str_length > max_length)
322
 
    Ptr[str_length=max_length]=0;
323
 
  else
324
 
  {
325
 
    if (realloc(max_length))
326
 
      return true;
327
 
    memset(Ptr+str_length, fill_char, max_length-str_length);
328
 
    str_length=max_length;
329
 
  }
330
 
  return false;
331
 
}
332
 
 
333
266
bool String::append(const String &s)
334
267
{
335
268
  if (s.length())