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
16
17
/* This file is for Chinese character sets GBK, created by Wei He
17
18
(hewei@mail.ied.ac.cn)
2694
** Calculate min_str and max_str that ranges a LIKE string.
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.
2706
** The function should return 0 if ok and 1 if the LIKE string can't be
2710
#define max_sort_char ((uchar) 255)
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,
2716
char *min_str,char *max_str,
2717
size_t *min_length,size_t *max_length)
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;
2724
for (; ptr != end && min_str != min_end && charlen > 0; ptr++, charlen--)
2726
if (ptr+1 != end && isgbkcode(ptr[0],ptr[1]))
2728
*min_str++= *max_str++ = *ptr++;
2729
*min_str++= *max_str++ = *ptr;
2732
if (*ptr == escape && ptr+1 != end)
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;
2741
if (*ptr == w_one) /* '_' in SQL */
2743
*min_str++='\0'; /* This should be min char */
2744
*max_str++=max_sort_char;
2747
if (*ptr == w_many) /* '%' in SQL */
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
2754
*min_length= ((cs->state & MY_CS_BINSORT) ? (size_t) (min_str - min_org) :
2756
*max_length= res_length;
2759
*max_str++= max_sort_char;
2760
} while (min_str != min_end);
2763
*min_str++= *max_str++ = *ptr;
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 */
2773
2694
static uint ismbchar_gbk(CHARSET_INFO *cs __attribute__((unused)),
2774
2695
const char* p, const char *e)