42
Converts a string into its sort key.
49
The my_strxfrm_xxx() function transforms a string pointed to by
50
'src' with length 'srclen' according to the charset+collation
51
pair 'cs' and copies the result key into 'dest'.
53
Comparing two strings using memcmp() after my_strnxfrm_xxx()
54
is equal to comparing two original strings with my_strnncollsp_xxx().
56
Not more than 'dstlen' bytes are written into 'dst'.
57
To garantee that the whole string is transformed, 'dstlen' must be
58
at least srclen*cs->strnxfrm_multiply bytes long. Otherwise,
59
consequent memcmp() may return a non-accurate result.
61
If the source string is too short to fill whole 'dstlen' bytes,
62
then the 'dest' string is padded up to 'dstlen', ensuring that:
68
my_strnxfrm_simple() is implemented for 8bit charsets and
69
simple collations with one-to-one string->key transformation.
71
See also implementations for various charsets/collations in
72
other ctype-xxx.c files.
81
size_t my_strnxfrm_simple(const CHARSET_INFO * const cs,
82
unsigned char *dst, size_t dstlen, uint32_t nweights,
83
const unsigned char *src, size_t srclen, uint32_t flags)
85
unsigned char *map= cs->sort_order;
86
unsigned char *d0= dst;
88
if ((frmlen= min((uint32_t)dstlen, nweights)) > srclen)
92
const unsigned char *end;
93
for (end= src + frmlen; src < end;)
98
const unsigned char *end;
99
for (end= dst + frmlen; dst < end; dst++)
100
*dst= map[(unsigned char) *dst];
102
return my_strxfrm_pad_desc_and_reverse(cs, d0, dst, d0 + dstlen,
103
nweights - frmlen, flags, 0);
107
int my_strnncoll_simple(const CHARSET_INFO * const cs, const unsigned char *s, size_t slen,
108
const unsigned char *t, size_t tlen,
111
size_t len = ( slen > tlen ) ? tlen : slen;
112
unsigned char *map= cs->sort_order;
113
if (t_is_prefix && slen > tlen)
117
if (map[*s++] != map[*t++])
118
return ((int) map[s[-1]] - (int) map[t[-1]]);
121
We can't use (slen - tlen) here as the result may be outside of the
122
precision of a signed int
124
return slen > tlen ? 1 : slen < tlen ? -1 : 0 ;
129
Compare strings, discarding end space
132
my_strnncollsp_simple()
133
cs character set handler
134
a First string to compare
135
a_length Length of 'a'
136
b Second string to compare
137
b_length Length of 'b'
138
diff_if_only_endspace_difference
139
Set to 1 if the strings should be regarded as different
140
if they only difference in end space
143
If one string is shorter as the other, then we space extend the other
144
so that the strings have equal length.
146
This will ensure that the following things hold:
158
int my_strnncollsp_simple(const CHARSET_INFO * const cs, const unsigned char *a, size_t a_length,
159
const unsigned char *b, size_t b_length,
160
bool diff_if_only_endspace_difference)
162
const unsigned char *map= cs->sort_order, *end;
166
#ifndef VARCHAR_WITH_DIFF_ENDSPACE_ARE_DIFFERENT_FOR_UNIQUE
167
diff_if_only_endspace_difference= 0;
170
end= a + (length= min(a_length, b_length));
173
if (map[*a++] != map[*b++])
174
return ((int) map[a[-1]] - (int) map[b[-1]]);
177
if (a_length != b_length)
180
if (diff_if_only_endspace_difference)
181
res= 1; /* Assume 'a' is bigger */
183
Check the next not space character of the longer key. If it's < ' ',
184
then it's smaller than the other key.
186
if (a_length < b_length)
188
/* put shorter key in s */
191
swap= -1; /* swap sign of result */
194
for (end= a + a_length-length; a < end ; a++)
197
return (map[*a] < ' ') ? -swap : swap;
204
size_t my_caseup_str_8bit(const CHARSET_INFO * const cs,char *str)
206
register unsigned char *map= cs->to_upper;
208
while ((*str= (char) map[(unsigned char) *str]) != 0)
210
return (size_t) (str - str_orig);
214
size_t my_casedn_str_8bit(const CHARSET_INFO * const cs,char *str)
216
register unsigned char *map= cs->to_lower;
218
while ((*str= (char) map[(unsigned char) *str]) != 0)
220
return (size_t) (str - str_orig);
224
size_t my_caseup_8bit(const CHARSET_INFO * const cs, char *src, size_t srclen,
225
char *dst, size_t dstlen)
227
assert(src == dst && srclen == dstlen);
228
char *end= src + srclen;
229
register unsigned char *map= cs->to_upper;
230
for ( ; src != end ; src++)
231
*src= (char) map[(unsigned char) *src];
236
size_t my_casedn_8bit(const CHARSET_INFO * const cs, char *src, size_t srclen,
237
char *dst, size_t dstlen)
239
assert(src == dst && srclen == dstlen);
240
char *end= src + srclen;
241
register unsigned char *map=cs->to_lower;
242
for ( ; src != end ; src++)
243
*src= (char) map[(unsigned char) *src];
247
int my_strcasecmp_8bit(const CHARSET_INFO * const cs,const char *s, const char *t)
249
register unsigned char *map=cs->to_upper;
250
while (map[(unsigned char) *s] == map[(unsigned char) *t++])
252
return ((int) map[(unsigned char) s[0]] - (int) map[(unsigned char) t[-1]]);
256
int my_mb_wc_8bit(const CHARSET_INFO * const cs,my_wc_t *wc,
257
const unsigned char *str,
258
const unsigned char *end)
261
return MY_CS_TOOSMALL;
263
*wc=cs->tab_to_uni[*str];
264
return (!wc[0] && str[0]) ? -1 : 1;
267
int my_wc_mb_8bit(const CHARSET_INFO * const cs,my_wc_t wc,
274
return MY_CS_TOOSMALL;
276
for (idx=cs->tab_from_uni; idx->tab ; idx++)
278
if (idx->from <= wc && idx->to >= wc)
280
str[0]= idx->tab[wc - idx->from];
281
return (!str[0] && wc) ? MY_CS_ILUNI : 1;
289
44
We can't use vsprintf here as it's not guaranteed to return
290
45
the length on all operating systems.
291
46
This function is also not called in a safe environment, so the