~ubuntu-branches/ubuntu/maverick/mysql-5.1/maverick-proposed

« back to all changes in this revision

Viewing changes to strings/ctype-gbk.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 14:16:05 UTC
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: package-import@ubuntu.com-20120222141605-nxlu9yzc6attylc2
Tags: upstream-5.1.61
ImportĀ upstreamĀ versionĀ 5.1.61

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000 MySQL AB
 
1
/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
2
2
 
3
3
   This program is free software; you can redistribute it and/or modify
4
4
   it under the terms of the GNU General Public License as published by
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 
15
*/
15
16
 
16
17
/* This file is for Chinese character sets GBK, created by Wei He 
17
18
   (hewei@mail.ied.ac.cn)
2690
2691
}
2691
2692
 
2692
2693
 
2693
 
/*
2694
 
** Calculate min_str and max_str that ranges a LIKE string.
2695
 
** Arguments:
2696
 
** ptr          Pointer to LIKE string.
2697
 
** ptr_length   Length of LIKE string.
2698
 
** escape       Escape character in LIKE.  (Normally '\').
2699
 
**              All escape characters should be removed from min_str and max_str
2700
 
** res_length   Length of min_str and max_str.
2701
 
** min_str      Smallest case sensitive string that ranges LIKE.
2702
 
**              Should be space padded to res_length.
2703
 
** max_str      Largest case sensitive string that ranges LIKE.
2704
 
**              Normally padded with the biggest character sort value.
2705
 
**
2706
 
** The function should return 0 if ok and 1 if the LIKE string can't be
2707
 
** optimized !
2708
 
*/
2709
 
 
2710
 
#define max_sort_char ((uchar) 255)
2711
 
 
2712
 
static my_bool my_like_range_gbk(CHARSET_INFO *cs __attribute__((unused)),
2713
 
                                 const char *ptr,size_t ptr_length,
2714
 
                                 pbool escape, pbool w_one, pbool w_many,
2715
 
                                 size_t res_length,
2716
 
                                 char *min_str,char *max_str,
2717
 
                                 size_t *min_length,size_t *max_length)
2718
 
{
2719
 
  const char *end= ptr + ptr_length;
2720
 
  char *min_org=min_str;
2721
 
  char *min_end=min_str+res_length;
2722
 
  size_t charlen= res_length / cs->mbmaxlen;
2723
 
 
2724
 
  for (; ptr != end && min_str != min_end && charlen > 0; ptr++, charlen--)
2725
 
  {
2726
 
    if (ptr+1 != end && isgbkcode(ptr[0],ptr[1]))
2727
 
    {
2728
 
      *min_str++= *max_str++ = *ptr++;
2729
 
      *min_str++= *max_str++ = *ptr;
2730
 
      continue;
2731
 
    }
2732
 
    if (*ptr == escape && ptr+1 != end)
2733
 
    {
2734
 
      ptr++;                            /* Skip escape */
2735
 
      if (isgbkcode(ptr[0], ptr[1]))
2736
 
        *min_str++= *max_str++ = *ptr;
2737
 
      if (min_str < min_end)
2738
 
        *min_str++= *max_str++= *ptr;
2739
 
      continue;
2740
 
    }
2741
 
    if (*ptr == w_one)          /* '_' in SQL */
2742
 
    {
2743
 
      *min_str++='\0';                  /* This should be min char */
2744
 
      *max_str++=max_sort_char;
2745
 
      continue;
2746
 
    }
2747
 
    if (*ptr == w_many)         /* '%' in SQL */
2748
 
    {
2749
 
      /*
2750
 
        Calculate length of keys:
2751
 
        'a\0\0... is the smallest possible string when we have space expand
2752
 
        a\ff\ff... is the biggest possible string
2753
 
      */
2754
 
      *min_length= ((cs->state & MY_CS_BINSORT) ? (size_t) (min_str - min_org) :
2755
 
                    res_length);
2756
 
      *max_length= res_length;
2757
 
      do {
2758
 
        *min_str++= 0;
2759
 
        *max_str++= max_sort_char;
2760
 
      } while (min_str != min_end);
2761
 
      return 0;
2762
 
    }
2763
 
    *min_str++= *max_str++ = *ptr;
2764
 
  }
2765
 
 
2766
 
  *min_length= *max_length = (size_t) (min_str - min_org);
2767
 
  while (min_str != min_end)
2768
 
    *min_str++= *max_str++= ' ';           /* Because if key compression */
2769
 
  return 0;
2770
 
}
2771
 
 
2772
 
 
2773
2694
static uint ismbchar_gbk(CHARSET_INFO *cs __attribute__((unused)),
2774
2695
                 const char* p, const char *e)
2775
2696
{
9983
9904
  my_strnncollsp_gbk,
9984
9905
  my_strnxfrm_gbk,
9985
9906
  my_strnxfrmlen_simple,
9986
 
  my_like_range_gbk,
 
9907
  my_like_range_mb,
9987
9908
  my_wildcmp_mb,
9988
9909
  my_strcasecmp_mb,
9989
9910
  my_instr_mb,
10048
9969
    1,                  /* mbminlen   */
10049
9970
    2,                  /* mbmaxlen */
10050
9971
    0,                  /* min_sort_char */
10051
 
    255,                /* max_sort_char */
 
9972
    0xA967,             /* max_sort_char */
10052
9973
    ' ',                /* pad char      */
10053
9974
    1,                  /* escape_with_backslash_is_dangerous */
10054
9975
    &my_charset_handler,
10080
10001
    1,                  /* mbminlen   */
10081
10002
    2,                  /* mbmaxlen */
10082
10003
    0,                  /* min_sort_char */
10083
 
    255,                /* max_sort_char */
 
10004
    0xFEFE,             /* max_sort_char */
10084
10005
    ' ',                /* pad char      */
10085
10006
    1,                  /* escape_with_backslash_is_dangerous */
10086
10007
    &my_charset_handler,