~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_string.cc

  • Committer: Brian Aker
  • Date: 2009-10-12 06:15:02 UTC
  • mfrom: (1165.1.178 static-functions)
  • Revision ID: brian@gaz-20091012061502-cds4m0cya7ow8sj7
Merge Stewart

Show diffs side-by-side

added added

removed removed

Lines of Context:
513
513
  Help functions
514
514
****************************************************************************/
515
515
 
516
 
 
517
 
 
518
 
/**
519
 
  Copy string with HEX-encoding of "bad" characters.
520
 
 
521
 
  @details This functions copies the string pointed by "src"
522
 
  to the string pointed by "dst". Not more than "srclen" bytes
523
 
  are read from "src". Any sequences of bytes representing
524
 
  a not-well-formed substring (according to cs) are hex-encoded,
525
 
  and all well-formed substrings (according to cs) are copied as is.
526
 
  Not more than "dstlen" bytes are written to "dst". The number
527
 
  of bytes written to "dst" is returned.
528
 
 
529
 
   @param      cs       character set pointer of the destination string
530
 
   @param[out] dst      destination string
531
 
   @param      dstlen   size of dst
532
 
   @param      src      source string
533
 
   @param      srclen   length of src
534
 
 
535
 
   @retval     result length
536
 
*/
537
 
 
538
 
size_t
539
 
my_copy_with_hex_escaping(const CHARSET_INFO * const cs,
540
 
                          char *dst, size_t dstlen,
541
 
                          const char *src, size_t srclen)
542
 
{
543
 
  const char *srcend= src + srclen;
544
 
  char *dst0= dst;
545
 
 
546
 
  for ( ; src < srcend ; )
547
 
  {
548
 
    size_t chlen;
549
 
    if ((chlen= my_ismbchar(cs, src, srcend)))
550
 
    {
551
 
      if (dstlen < chlen)
552
 
        break;
553
 
      memcpy(dst, src, chlen);
554
 
      src+= chlen;
555
 
      dst+= chlen;
556
 
      dstlen-= chlen;
557
 
    }
558
 
    else if (*src & 0x80)
559
 
    {
560
 
      if (dstlen < 4)
561
 
        break;
562
 
      *dst++= '\\';
563
 
      *dst++= 'x';
564
 
      *dst++= _dig_vec_upper[((unsigned char) *src) >> 4];
565
 
      *dst++= _dig_vec_upper[((unsigned char) *src) & 15];
566
 
      src++;
567
 
      dstlen-= 4;
568
 
    }
569
 
    else
570
 
    {
571
 
      if (dstlen < 1)
572
 
        break;
573
 
      *dst++= *src++;
574
 
      dstlen--;
575
 
    }
576
 
  }
577
 
  return dst - dst0;
578
 
}
579
 
 
580
516
/*
581
517
  copy a string,
582
518
  with optional character set conversion,