summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.in3
-rw-r--r--strings/ctype-big5.c86
-rw-r--r--strings/ctype-cp932.c77
-rw-r--r--strings/ctype-euc_kr.c4
-rw-r--r--strings/ctype-eucjpms.c4
-rw-r--r--strings/ctype-gb2312.c4
-rw-r--r--strings/ctype-gbk.c86
-rw-r--r--strings/ctype-mb.c22
-rw-r--r--strings/ctype-sjis.c86
-rw-r--r--strings/ctype-ujis.c4
-rw-r--r--unittest/Makefile.am4
-rw-r--r--unittest/strings/Makefile.am27
-rw-r--r--unittest/strings/strings-t.c114
13 files changed, 181 insertions, 340 deletions
diff --git a/configure.in b/configure.in
index 97597e2a8b9..b65418957ea 100644
--- a/configure.in
+++ b/configure.in
@@ -3035,7 +3035,8 @@ fi
AC_CONFIG_FILES(Makefile extra/Makefile mysys/Makefile dnl
unittest/Makefile unittest/mytap/Makefile unittest/mytap/t/Makefile dnl
- unittest/mysys/Makefile unittest/examples/Makefile dnl
+ unittest/mysys/Makefile unittest/strings/Makefile dnl
+ unittest/examples/Makefile dnl
strings/Makefile regex/Makefile storage/Makefile dnl
man/Makefile BUILD/Makefile vio/Makefile dnl
libmysql/Makefile libmysql_r/Makefile client/Makefile dnl
diff --git a/strings/ctype-big5.c b/strings/ctype-big5.c
index f5221bb3a21..3007d76a5a4 100644
--- a/strings/ctype-big5.c
+++ b/strings/ctype-big5.c
@@ -994,86 +994,6 @@ static int my_strxfrm_big5(uchar *dest, const uchar *src, int len)
#endif
-/*
-** Calculate min_str and max_str that ranges a LIKE string.
-** Arguments:
-** ptr Pointer to LIKE string.
-** ptr_length Length of LIKE string.
-** escape Escape character in LIKE. (Normally '\').
-** All escape characters should be removed from min_str and max_str
-** res_length Length of min_str and max_str.
-** min_str Smallest case sensitive string that ranges LIKE.
-** Should be space padded to res_length.
-** max_str Largest case sensitive string that ranges LIKE.
-** Normally padded with the biggest character sort value.
-**
-** The function should return 0 if ok and 1 if the LIKE string can't be
-** optimized !
-*/
-
-#define max_sort_char ((char) 255)
-
-static my_bool my_like_range_big5(CHARSET_INFO *cs __attribute__((unused)),
- const char *ptr,size_t ptr_length,
- pbool escape, pbool w_one, pbool w_many,
- size_t res_length,
- char *min_str, char *max_str,
- size_t *min_length, size_t *max_length)
-{
- const char *end= ptr + ptr_length;
- char *min_org=min_str;
- char *min_end=min_str+res_length;
- size_t charlen= res_length / cs->mbmaxlen;
-
- for (; ptr != end && min_str != min_end && charlen > 0; ptr++, charlen--)
- {
- if (ptr+1 != end && isbig5code(ptr[0],ptr[1]))
- {
- *min_str++= *max_str++ = *ptr++;
- *min_str++= *max_str++ = *ptr;
- continue;
- }
- if (*ptr == escape && ptr+1 != end)
- {
- ptr++; /* Skip escape */
- if (isbig5code(ptr[0], ptr[1]))
- *min_str++= *max_str++ = *ptr++;
- if (min_str < min_end)
- *min_str++= *max_str++= *ptr;
- continue;
- }
- if (*ptr == w_one) /* '_' in SQL */
- {
- *min_str++='\0'; /* This should be min char */
- *max_str++=max_sort_char;
- continue;
- }
- if (*ptr == w_many) /* '%' in SQL */
- {
- /*
- Calculate length of keys:
- 'a\0\0... is the smallest possible string when we have space expand
- a\ff\ff... is the biggest possible string
- */
- *min_length= ((cs->state & MY_CS_BINSORT) ? (size_t) (min_str - min_org) :
- res_length);
- *max_length= res_length;
- do {
- *min_str++ = 0;
- *max_str++ = max_sort_char;
- } while (min_str != min_end);
- return 0;
- }
- *min_str++= *max_str++ = *ptr;
- }
-
- *min_length= *max_length= (size_t) (min_str-min_org);
- while (min_str != min_end)
- *min_str++= *max_str++= ' ';
- return 0;
-}
-
-
static uint ismbchar_big5(CHARSET_INFO *cs __attribute__((unused)),
const char* p, const char *e)
{
@@ -6955,7 +6875,7 @@ static MY_COLLATION_HANDLER my_collation_big5_chinese_ci_handler =
my_strnncollsp_big5,
my_strnxfrm_big5,
my_strnxfrmlen_simple,
- my_like_range_big5,
+ my_like_range_mb,
my_wildcmp_mb,
my_strcasecmp_mb,
my_instr_mb,
@@ -7019,7 +6939,7 @@ CHARSET_INFO my_charset_big5_chinese_ci=
1, /* mbminlen */
2, /* mbmaxlen */
0, /* min_sort_char */
- 255, /* max_sort_char */
+ 0xF9D5, /* max_sort_char */
' ', /* pad char */
1, /* escape_with_backslash_is_dangerous */
&my_charset_big5_handler,
@@ -7052,7 +6972,7 @@ CHARSET_INFO my_charset_big5_bin=
1, /* mbminlen */
2, /* mbmaxlen */
0, /* min_sort_char */
- 255, /* max_sort_char */
+ 0xF9FE, /* max_sort_char */
' ', /* pad char */
1, /* escape_with_backslash_is_dangerous */
&my_charset_big5_handler,
diff --git a/strings/ctype-cp932.c b/strings/ctype-cp932.c
index 67555ac4384..df4083c9f8d 100644
--- a/strings/ctype-cp932.c
+++ b/strings/ctype-cp932.c
@@ -1812,77 +1812,6 @@ static size_t my_strnxfrm_cp932(CHARSET_INFO *cs __attribute__((unused)),
}
-/*
-** Calculate min_str and max_str that ranges a LIKE string.
-** Arguments:
-** ptr Pointer to LIKE string.
-** ptr_length Length of LIKE string.
-** escape Escape character in LIKE. (Normally '\').
-** All escape characters should be removed from min_str and max_str
-** res_length Length of min_str and max_str.
-** min_str Smallest case sensitive string that ranges LIKE.
-** Should be space padded to res_length.
-** max_str Largest case sensitive string that ranges LIKE.
-** Normally padded with the biggest character sort value.
-**
-** The function should return 0 if ok and 1 if the LIKE string can't be
-** optimized !
-*/
-
-#define max_sort_char ((char) 255)
-
-static my_bool my_like_range_cp932(CHARSET_INFO *cs __attribute__((unused)),
- const char *ptr,size_t ptr_length,
- pbool escape, pbool w_one, pbool w_many,
- size_t res_length,
- char *min_str,char *max_str,
- size_t *min_length, size_t *max_length)
-{
- const char *end=ptr+ptr_length;
- char *min_org=min_str;
- char *min_end=min_str+res_length;
-
- while (ptr < end && min_str < min_end) {
- if (ismbchar_cp932(cs, ptr, end)) {
- *min_str++ = *max_str++ = *ptr++;
- if (min_str < min_end)
- *min_str++ = *max_str++ = *ptr++;
- continue;
- }
- if (*ptr == escape && ptr+1 < end) {
- ptr++; /* Skip escape */
- if (ismbchar_cp932(cs, ptr, end))
- *min_str++ = *max_str++ = *ptr++;
- if (min_str < min_end)
- *min_str++ = *max_str++ = *ptr++;
- continue;
- }
- if (*ptr == w_one) { /* '_' in SQL */
- *min_str++ = '\0'; /* This should be min char */
- *max_str++ = max_sort_char;
- ptr++;
- continue;
- }
- if (*ptr == w_many)
- { /* '%' in SQL */
- *min_length = (size_t)(min_str - min_org);
- *max_length = res_length;
- do
- {
- *min_str++= 0;
- *max_str++= max_sort_char;
- } while (min_str < min_end);
- return 0;
- }
- *min_str++ = *max_str++ = *ptr++;
- }
- *min_length = *max_length = (size_t) (min_str - min_org);
- while (min_str < min_end)
- *min_str++ = *max_str++ = ' '; /* Because if key compression */
- return 0;
-}
-
-
static uint16 cp932_to_unicode[65536]=
{
0x0000, 0x0001, 0x0002, 0x0003, /* 0000 */
@@ -34852,7 +34781,7 @@ static MY_COLLATION_HANDLER my_collation_ci_handler =
my_strnncollsp_cp932,
my_strnxfrm_cp932,
my_strnxfrmlen_simple,
- my_like_range_cp932,
+ my_like_range_mb,
my_wildcmp_mb, /* wildcmp */
my_strcasecmp_8bit,
my_instr_mb,
@@ -34918,7 +34847,7 @@ CHARSET_INFO my_charset_cp932_japanese_ci=
1, /* mbminlen */
2, /* mbmaxlen */
0, /* min_sort_char */
- 255, /* max_sort_char */
+ 0xFCFC, /* max_sort_char */
' ', /* pad char */
1, /* escape_with_backslash_is_dangerous */
&my_charset_handler,
@@ -34950,7 +34879,7 @@ CHARSET_INFO my_charset_cp932_bin=
1, /* mbminlen */
2, /* mbmaxlen */
0, /* min_sort_char */
- 255, /* max_sort_char */
+ 0xFCFC, /* max_sort_char */
' ', /* pad char */
1, /* escape_with_backslash_is_dangerous */
&my_charset_handler,
diff --git a/strings/ctype-euc_kr.c b/strings/ctype-euc_kr.c
index c2067ac6f6b..7329f9ec09a 100644
--- a/strings/ctype-euc_kr.c
+++ b/strings/ctype-euc_kr.c
@@ -10029,7 +10029,7 @@ CHARSET_INFO my_charset_euckr_korean_ci=
1, /* mbminlen */
2, /* mbmaxlen */
0, /* min_sort_char */
- 255, /* max_sort_char */
+ 0xFEFE, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
&my_charset_handler,
@@ -10062,7 +10062,7 @@ CHARSET_INFO my_charset_euckr_bin=
1, /* mbminlen */
2, /* mbmaxlen */
0, /* min_sort_char */
- 255, /* max_sort_char */
+ 0xFEFE, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
&my_charset_handler,
diff --git a/strings/ctype-eucjpms.c b/strings/ctype-eucjpms.c
index 25c15a08d4e..6180e0e1a7a 100644
--- a/strings/ctype-eucjpms.c
+++ b/strings/ctype-eucjpms.c
@@ -67573,7 +67573,7 @@ CHARSET_INFO my_charset_eucjpms_japanese_ci=
1, /* mbminlen */
3, /* mbmaxlen */
0, /* min_sort_char */
- 255, /* max_sort_char */
+ 0xFEFE, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
&my_charset_handler,
@@ -67606,7 +67606,7 @@ CHARSET_INFO my_charset_eucjpms_bin=
1, /* mbminlen */
3, /* mbmaxlen */
0, /* min_sort_char */
- 255, /* max_sort_char */
+ 0xFEFE, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
&my_charset_handler,
diff --git a/strings/ctype-gb2312.c b/strings/ctype-gb2312.c
index 46f3e9c6da5..b1acd643df3 100644
--- a/strings/ctype-gb2312.c
+++ b/strings/ctype-gb2312.c
@@ -6432,7 +6432,7 @@ CHARSET_INFO my_charset_gb2312_chinese_ci=
1, /* mbminlen */
2, /* mbmaxlen */
0, /* min_sort_char */
- 255, /* max_sort_char */
+ 0xF7FE, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
&my_charset_handler,
@@ -6464,7 +6464,7 @@ CHARSET_INFO my_charset_gb2312_bin=
1, /* mbminlen */
2, /* mbmaxlen */
0, /* min_sort_char */
- 255, /* max_sort_char */
+ 0xF7FE, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
&my_charset_handler,
diff --git a/strings/ctype-gbk.c b/strings/ctype-gbk.c
index 609bc2ecd27..547c8821229 100644
--- a/strings/ctype-gbk.c
+++ b/strings/ctype-gbk.c
@@ -3548,86 +3548,6 @@ static size_t my_strnxfrm_gbk(CHARSET_INFO *cs __attribute__((unused)),
}
-/*
-** Calculate min_str and max_str that ranges a LIKE string.
-** Arguments:
-** ptr Pointer to LIKE string.
-** ptr_length Length of LIKE string.
-** escape Escape character in LIKE. (Normally '\').
-** All escape characters should be removed from min_str and max_str
-** res_length Length of min_str and max_str.
-** min_str Smallest case sensitive string that ranges LIKE.
-** Should be space padded to res_length.
-** max_str Largest case sensitive string that ranges LIKE.
-** Normally padded with the biggest character sort value.
-**
-** The function should return 0 if ok and 1 if the LIKE string can't be
-** optimized !
-*/
-
-#define max_sort_char ((uchar) 255)
-
-static my_bool my_like_range_gbk(CHARSET_INFO *cs __attribute__((unused)),
- const char *ptr,size_t ptr_length,
- pbool escape, pbool w_one, pbool w_many,
- size_t res_length,
- char *min_str,char *max_str,
- size_t *min_length,size_t *max_length)
-{
- const char *end= ptr + ptr_length;
- char *min_org=min_str;
- char *min_end=min_str+res_length;
- size_t charlen= res_length / cs->mbmaxlen;
-
- for (; ptr != end && min_str != min_end && charlen > 0; ptr++, charlen--)
- {
- if (ptr+1 != end && isgbkcode(ptr[0],ptr[1]))
- {
- *min_str++= *max_str++ = *ptr++;
- *min_str++= *max_str++ = *ptr;
- continue;
- }
- if (*ptr == escape && ptr+1 != end)
- {
- ptr++; /* Skip escape */
- if (isgbkcode(ptr[0], ptr[1]))
- *min_str++= *max_str++ = *ptr;
- if (min_str < min_end)
- *min_str++= *max_str++= *ptr;
- continue;
- }
- if (*ptr == w_one) /* '_' in SQL */
- {
- *min_str++='\0'; /* This should be min char */
- *max_str++=max_sort_char;
- continue;
- }
- if (*ptr == w_many) /* '%' in SQL */
- {
- /*
- Calculate length of keys:
- 'a\0\0... is the smallest possible string when we have space expand
- a\ff\ff... is the biggest possible string
- */
- *min_length= ((cs->state & MY_CS_BINSORT) ? (size_t) (min_str - min_org) :
- res_length);
- *max_length= res_length;
- do {
- *min_str++= 0;
- *max_str++= max_sort_char;
- } while (min_str != min_end);
- return 0;
- }
- *min_str++= *max_str++ = *ptr;
- }
-
- *min_length= *max_length = (size_t) (min_str - min_org);
- while (min_str != min_end)
- *min_str++= *max_str++= ' '; /* Because if key compression */
- return 0;
-}
-
-
static uint ismbchar_gbk(CHARSET_INFO *cs __attribute__((unused)),
const char* p, const char *e)
{
@@ -10841,7 +10761,7 @@ static MY_COLLATION_HANDLER my_collation_ci_handler =
my_strnncollsp_gbk,
my_strnxfrm_gbk,
my_strnxfrmlen_simple,
- my_like_range_gbk,
+ my_like_range_mb,
my_wildcmp_mb,
my_strcasecmp_mb,
my_instr_mb,
@@ -10906,7 +10826,7 @@ CHARSET_INFO my_charset_gbk_chinese_ci=
1, /* mbminlen */
2, /* mbmaxlen */
0, /* min_sort_char */
- 255, /* max_sort_char */
+ 0xA967, /* max_sort_char */
' ', /* pad char */
1, /* escape_with_backslash_is_dangerous */
&my_charset_handler,
@@ -10938,7 +10858,7 @@ CHARSET_INFO my_charset_gbk_bin=
1, /* mbminlen */
2, /* mbmaxlen */
0, /* min_sort_char */
- 255, /* max_sort_char */
+ 0xFEFE, /* max_sort_char */
' ', /* pad char */
1, /* escape_with_backslash_is_dangerous */
&my_charset_handler,
diff --git a/strings/ctype-mb.c b/strings/ctype-mb.c
index b1b381da59e..b2f2e3cd22e 100644
--- a/strings/ctype-mb.c
+++ b/strings/ctype-mb.c
@@ -604,7 +604,9 @@ my_hash_sort_mb_bin(CHARSET_INFO *cs __attribute__((unused)),
DESCRIPTION
Write max key:
- for non-Unicode character sets:
- just set to 255.
+ just bfill using max_sort_char if max_sort_char is one byte.
+ In case when max_sort_char is two bytes, fill with double-byte pairs
+ and optionally pad with a single space character.
- for Unicode character set (utf-8):
create a buffer with multibyte representation of the max_sort_char
character, and copy it into max_str in a loop.
@@ -616,12 +618,20 @@ static void pad_max_char(CHARSET_INFO *cs, char *str, char *end)
if (!(cs->state & MY_CS_UNICODE))
{
- bfill(str, end - str, 255);
- return;
+ if (cs->max_sort_char <= 255)
+ {
+ bfill(str, end - str, cs->max_sort_char);
+ return;
+ }
+ buf[0]= cs->max_sort_char >> 8;
+ buf[1]= cs->max_sort_char & 0xFF;
+ buflen= 2;
+ }
+ else
+ {
+ buflen= cs->cset->wc_mb(cs, cs->max_sort_char, (uchar*) buf,
+ (uchar*) buf + sizeof(buf));
}
-
- buflen= cs->cset->wc_mb(cs, cs->max_sort_char, (uchar*) buf,
- (uchar*) buf + sizeof(buf));
DBUG_ASSERT(buflen > 0);
do
diff --git a/strings/ctype-sjis.c b/strings/ctype-sjis.c
index 90c76dc3c79..91adf4ebddf 100644
--- a/strings/ctype-sjis.c
+++ b/strings/ctype-sjis.c
@@ -1179,86 +1179,6 @@ static size_t my_strnxfrm_sjis(CHARSET_INFO *cs __attribute__((unused)),
}
-/*
-** Calculate min_str and max_str that ranges a LIKE string.
-** Arguments:
-** ptr Pointer to LIKE string.
-** ptr_length Length of LIKE string.
-** escape Escape character in LIKE. (Normally '\').
-** All escape characters should be removed from min_str and max_str
-** res_length Length of min_str and max_str.
-** min_str Smallest case sensitive string that ranges LIKE.
-** Should be space padded to res_length.
-** max_str Largest case sensitive string that ranges LIKE.
-** Normally padded with the biggest character sort value.
-**
-** The function should return 0 if ok and 1 if the LIKE string can't be
-** optimized !
-*/
-
-#define max_sort_char ((char) 255)
-
-static my_bool my_like_range_sjis(CHARSET_INFO *cs __attribute__((unused)),
- const char *ptr,size_t ptr_length,
- pbool escape, pbool w_one, pbool w_many,
- size_t res_length,
- char *min_str,char *max_str,
- size_t *min_length,size_t *max_length)
-{
- const char *end= ptr + ptr_length;
- char *min_org=min_str;
- char *min_end=min_str+res_length;
- size_t charlen= res_length / cs->mbmaxlen;
-
- for ( ; ptr < end && min_str < min_end && charlen > 0 ; charlen--)
- {
- if (ismbchar_sjis(cs, ptr, end)) {
- *min_str++ = *max_str++ = *ptr++;
- if (min_str < min_end)
- *min_str++ = *max_str++ = *ptr++;
- continue;
- }
- if (*ptr == escape && ptr+1 < end) {
- ptr++; /* Skip escape */
- if (ismbchar_sjis(cs, ptr, end))
- *min_str++ = *max_str++ = *ptr++;
- if (min_str < min_end)
- *min_str++ = *max_str++ = *ptr++;
- continue;
- }
- if (*ptr == w_one) { /* '_' in SQL */
- *min_str++ = '\0'; /* This should be min char */
- *max_str++ = max_sort_char;
- ptr++;
- continue;
- }
- if (*ptr == w_many)
- { /* '%' in SQL */
- /*
- Calculate length of keys:
- 'a\0\0... is the smallest possible string when we have space expand
- a\ff\ff... is the biggest possible string
- */
- *min_length= ((cs->state & MY_CS_BINSORT) ? (size_t) (min_str - min_org) :
- res_length);
- *max_length= res_length;
- do
- {
- *min_str++= 0;
- *max_str++= max_sort_char;
- } while (min_str < min_end);
- return 0;
- }
- *min_str++ = *max_str++ = *ptr++;
- }
-
- *min_length= *max_length= (size_t) (min_str - min_org);
- while (min_str != min_end)
- *min_str++= *max_str++= ' '; /* Because if key compression */
- return 0;
-}
-
-
/* SJIS->Unicode conversion table */
static uint16 sjis_to_unicode[65536]=
{
@@ -34231,7 +34151,7 @@ static MY_COLLATION_HANDLER my_collation_ci_handler =
my_strnncollsp_sjis,
my_strnxfrm_sjis,
my_strnxfrmlen_simple,
- my_like_range_sjis,
+ my_like_range_mb,
my_wildcmp_mb, /* wildcmp */
my_strcasecmp_8bit,
my_instr_mb,
@@ -34297,7 +34217,7 @@ CHARSET_INFO my_charset_sjis_japanese_ci=
1, /* mbminlen */
2, /* mbmaxlen */
0, /* min_sort_char */
- 255, /* max_sort_char */
+ 0xFCFC, /* max_sort_char */
' ', /* pad char */
1, /* escape_with_backslash_is_dangerous */
&my_charset_handler,
@@ -34329,7 +34249,7 @@ CHARSET_INFO my_charset_sjis_bin=
1, /* mbminlen */
2, /* mbmaxlen */
0, /* min_sort_char */
- 255, /* max_sort_char */
+ 0xFCFC, /* max_sort_char */
' ', /* pad char */
1, /* escape_with_backslash_is_dangerous */
&my_charset_handler,
diff --git a/strings/ctype-ujis.c b/strings/ctype-ujis.c
index 4fabbdbaeb3..9f4d032ffe0 100644
--- a/strings/ctype-ujis.c
+++ b/strings/ctype-ujis.c
@@ -67316,7 +67316,7 @@ CHARSET_INFO my_charset_ujis_japanese_ci=
1, /* mbminlen */
3, /* mbmaxlen */
0, /* min_sort_char */
- 255, /* max_sort_char */
+ 0xFEFE, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
&my_charset_handler,
@@ -67349,7 +67349,7 @@ CHARSET_INFO my_charset_ujis_bin=
1, /* mbminlen */
3, /* mbmaxlen */
0, /* min_sort_char */
- 255, /* max_sort_char */
+ 0xFEFE, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
&my_charset_handler,
diff --git a/unittest/Makefile.am b/unittest/Makefile.am
index 6197586b008..da655d1844e 100644
--- a/unittest/Makefile.am
+++ b/unittest/Makefile.am
@@ -13,12 +13,12 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-SUBDIRS = mytap . mysys examples
+SUBDIRS = mytap . mysys examples strings
EXTRA_DIST = unit.pl
CLEANFILES = unit
-unittests = mytap mysys @mysql_se_unittest_dirs@ @mysql_pg_unittest_dirs@
+unittests = mytap mysys strings @mysql_se_unittest_dirs@ @mysql_pg_unittest_dirs@
test:
perl unit.pl run $(unittests)
diff --git a/unittest/strings/Makefile.am b/unittest/strings/Makefile.am
new file mode 100644
index 00000000000..5b18d89f58e
--- /dev/null
+++ b/unittest/strings/Makefile.am
@@ -0,0 +1,27 @@
+# Copyright 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+AM_CPPFLAGS = @ZLIB_INCLUDES@ -I$(top_builddir)/include
+AM_CPPFLAGS += -I$(top_srcdir)/include -I$(top_srcdir)/unittest/mytap
+
+LDADD = $(top_builddir)/unittest/mytap/libmytap.a \
+ $(top_builddir)/mysys/libmysys.a \
+ $(top_builddir)/dbug/libdbug.a \
+ $(top_builddir)/strings/libmystrings.a
+
+noinst_PROGRAMS = strings-t
+
+# Don't update the files from bitkeeper
+%::SCCS/s.%
diff --git a/unittest/strings/strings-t.c b/unittest/strings/strings-t.c
new file mode 100644
index 00000000000..2d246cfa17f
--- /dev/null
+++ b/unittest/strings/strings-t.c
@@ -0,0 +1,114 @@
+/* Copyright 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+
+#include <tap.h>
+#include <my_global.h>
+#include <my_sys.h>
+
+
+/*
+ Test that like_range() returns well-formed results.
+*/
+static int
+test_like_range_for_charset(CHARSET_INFO *cs, const char *src, size_t src_len)
+{
+ char min_str[32], max_str[32];
+ size_t min_len, max_len, min_well_formed_len, max_well_formed_len;
+ int error= 0;
+
+ cs->coll->like_range(cs, src, src_len, '\\', '_', '%',
+ sizeof(min_str), min_str, max_str, &min_len, &max_len);
+ diag("min_len=%d\tmax_len=%d\t%s", min_len, max_len, cs->name);
+ min_well_formed_len= cs->cset->well_formed_len(cs,
+ min_str, min_str + min_len,
+ 10000, &error);
+ max_well_formed_len= cs->cset->well_formed_len(cs,
+ max_str, max_str + max_len,
+ 10000, &error);
+ if (min_len != min_well_formed_len)
+ diag("Bad min_str: min_well_formed_len=%d min_str[%d]=0x%02X",
+ min_well_formed_len, min_well_formed_len,
+ (uchar) min_str[min_well_formed_len]);
+ if (max_len != max_well_formed_len)
+ diag("Bad max_str: max_well_formed_len=%d max_str[%d]=0x%02X",
+ max_well_formed_len, max_well_formed_len,
+ (uchar) max_str[max_well_formed_len]);
+ return
+ min_len == min_well_formed_len &&
+ max_len == max_well_formed_len ? 0 : 1;
+}
+
+
+static CHARSET_INFO *charset_list[]=
+{
+#ifdef HAVE_CHARSET_big5
+ &my_charset_big5_chinese_ci,
+ &my_charset_big5_bin,
+#endif
+#ifdef HAVE_CHARSET_euckr
+ &my_charset_euckr_korean_ci,
+ &my_charset_euckr_bin,
+#endif
+#ifdef HAVE_CHARSET_gb2312
+ &my_charset_gb2312_chinese_ci,
+ &my_charset_gb2312_bin,
+#endif
+#ifdef HAVE_CHARSET_gbk
+ &my_charset_gbk_chinese_ci,
+ &my_charset_gbk_bin,
+#endif
+#ifdef HAVE_CHARSET_latin1
+ &my_charset_latin1,
+ &my_charset_latin1_bin,
+#endif
+#ifdef HAVE_CHARSET_sjis
+ &my_charset_sjis_japanese_ci,
+ &my_charset_sjis_bin,
+#endif
+#ifdef HAVE_CHARSET_tis620
+ &my_charset_tis620_thai_ci,
+ &my_charset_tis620_bin,
+#endif
+#ifdef HAVE_CHARSET_ujis
+ &my_charset_ujis_japanese_ci,
+ &my_charset_ujis_bin,
+#endif
+#ifdef HAVE_CHARSET_utf8
+ &my_charset_utf8_general_ci,
+ &my_charset_utf8_unicode_ci,
+ &my_charset_utf8_bin,
+#endif
+};
+
+
+int main()
+{
+ size_t i, failed= 0;
+
+ plan(1);
+ diag("Testing my_like_range_xxx() functions");
+
+ for (i= 0; i < array_elements(charset_list); i++)
+ {
+ CHARSET_INFO *cs= charset_list[i];
+ if (test_like_range_for_charset(cs, "abc%", 4))
+ {
+ ++failed;
+ diag("Failed for %s", cs->name);
+ }
+ }
+ ok(failed == 0, "Testing my_like_range_xxx() functions");
+ return exit_status();
+}