summaryrefslogtreecommitdiff
path: root/strings/strcoll.ic
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2016-03-23 14:26:43 +0400
committerAlexander Barkov <bar@mariadb.org>2016-03-23 14:26:43 +0400
commit0a83caf4a90cc98281571404dfc9ee3a718120d8 (patch)
treef92abd9a7cc951227ba820c4b51198d18d4b29ca /strings/strcoll.ic
parent0d42d4e9e02074416e0149ada0edd584cbb233a6 (diff)
downloadmariadb-git-0a83caf4a90cc98281571404dfc9ee3a718120d8.tar.gz
Removing duplicate code: sharing implementation of "strnxfrm"
between gbk_chinese_ci and big5_chinese_ci.
Diffstat (limited to 'strings/strcoll.ic')
-rw-r--r--strings/strcoll.ic41
1 files changed, 41 insertions, 0 deletions
diff --git a/strings/strcoll.ic b/strings/strcoll.ic
index 4bced593a23..4ce362c1675 100644
--- a/strings/strcoll.ic
+++ b/strings/strcoll.ic
@@ -262,6 +262,45 @@ MY_FUNCTION_NAME(strnncollsp)(CHARSET_INFO *cs __attribute__((unused)),
return 0;
}
+
+#ifdef DEFINE_STRNXFRM
+#ifndef WEIGHT_MB2_FRM
+#define WEIGHT_MB2_FRM(x,y) WEIGHT_MB2(x,y)
+#endif
+
+static size_t
+MY_FUNCTION_NAME(strnxfrm)(CHARSET_INFO *cs,
+ uchar *dst, size_t dstlen, uint nweights,
+ const uchar *src, size_t srclen, uint flags)
+{
+ uchar *d0= dst;
+ uchar *de= dst + dstlen;
+ const uchar *se= src + srclen;
+ const uchar *sort_order= cs->sort_order;
+
+ for (; dst < de && src < se && nweights; nweights--)
+ {
+ if (my_charlen(cs, (const char *) src, (const char *) se) > 1)
+ {
+ /*
+ Note, it is safe not to check (src < se)
+ in the code below, because my_charlen() would
+ not return 2 if src was too short
+ */
+ uint16 e= WEIGHT_MB2_FRM(src[0], src[1]);
+ *dst++= (uchar) (e >> 8);
+ if (dst < de)
+ *dst++= (uchar) (e & 0xFF);
+ src+= 2;
+ }
+ else
+ *dst++= sort_order ? sort_order[*src++] : *src++;
+ }
+ return my_strxfrm_pad_desc_and_reverse(cs, d0, dst, de, nweights, flags, 0);
+}
+#endif /* DEFINE_STRNXFRM */
+
+
/*
We usually include this file at least two times from the same source file,
for the _ci and the _bin collations. Prepare for the second inclusion.
@@ -273,3 +312,5 @@ MY_FUNCTION_NAME(strnncollsp)(CHARSET_INFO *cs __attribute__((unused)),
#undef WEIGHT_MB3
#undef WEIGHT_MB4
#undef WEIGHT_PAD_SPACE
+#undef WEIGHT_MB2_FRM
+#undef DEFINE_STRNXFRM