Coverage Report

Created: 2025-06-13 07:09

/src/server/strings/strings_def.h
Line
Count
Source (jump to first uncovered line)
1
#ifndef STRINGS_DEF_INCLUDED
2
#define STRINGS_DEF_INCLUDED
3
/* Copyright (C) 2011 Monty Program Ab
4
5
   This program is free software; you can redistribute it and/or modify
6
   it under the terms of the GNU General Public License as published by
7
   the Free Software Foundation; version 2 of the License.
8
9
   This program is distributed in the hope that it will be useful,
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
   GNU General Public License for more details.
13
14
   You should have received a copy of the GNU General Public License
15
   along with this program; if not, write to the Free Software
16
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
17
18
/* This file is to be include first in all files in the string directory */
19
20
#undef DBUG_ASSERT_AS_PRINTF
21
#include <my_global.h>    /* Define standard vars */
22
#include "m_string.h"   /* Exernal definitions of string functions */
23
#include "m_ctype.h"
24
25
/*
26
  We can't use the original DBUG_ASSERT() (which includes _db_flush())
27
  in the strings library as libdbug is compiled after the the strings
28
  library and we don't want to have strings depending on libdbug which
29
  depends on mysys and strings.
30
*/
31
32
#if !defined(DBUG_OFF)
33
#undef DBUG_ASSERT
34
#define DBUG_ASSERT(A) assert(A)
35
#endif
36
37
#define MY_NOPAD_ID(x)  ((x)+0x400)
38
39
/* SPACE_INT is a word that contains only spaces */
40
#if SIZEOF_INT == 4
41
0
#define SPACE_INT 0x20202020
42
#elif SIZEOF_INT == 8
43
#define SPACE_INT 0x2020202020202020
44
#else
45
#error define the appropriate constant for a word full of spaces
46
#endif
47
48
/**
49
  Skip trailing space.
50
51
  On most systems reading memory in larger chunks (ideally equal to the size of
52
  the chinks that the machine physically reads from memory) causes fewer memory
53
  access loops and hence increased performance.
54
  This is why the 'int' type is used : it's closest to that (according to how
55
  it's defined in C).
56
  So when we determine the amount of whitespace at the end of a string we do
57
  the following :
58
    1. We divide the string into 3 zones :
59
      a) from the start of the string (__start) to the first multiple
60
        of sizeof(int)  (__start_words)
61
      b) from the end of the string (__end) to the last multiple of sizeof(int)
62
        (__end_words)
63
      c) a zone that is aligned to sizeof(int) and can be safely accessed
64
        through an int *
65
    2. We start comparing backwards from (c) char-by-char. If all we find is
66
       space then we continue
67
    3. If there are elements in zone (b) we compare them as unsigned ints to a
68
       int mask (SPACE_INT) consisting of all spaces
69
    4. Finally we compare the remaining part (a) of the string char by char.
70
       This covers for the last non-space unsigned int from 3. (if any)
71
72
   This algorithm works well for relatively larger strings, but it will slow
73
   the things down for smaller strings (because of the additional calculations
74
   and checks compared to the naive method). Thus the barrier of length 20
75
   is added.
76
77
   @param     ptr   pointer to the input string
78
   @param     len   the length of the string
79
   @return          the last non-space character
80
*/
81
82
static inline const uchar *skip_trailing_space(const uchar *ptr,size_t len)
83
0
{
84
0
  const uchar *end= ptr + len;
85
0
  DBUG_ASSERT(ptr); /* Avoid UBSAN nullptr-with-offset */
86
0
  if (len > 20)
87
0
  {
88
0
    const uchar *end_words= (const uchar *)(intptr)
89
0
      (((ulonglong)(intptr)end) / SIZEOF_INT * SIZEOF_INT);
90
0
    const uchar *start_words= (const uchar *)(intptr)
91
0
       ((((ulonglong)(intptr)ptr) + SIZEOF_INT - 1) / SIZEOF_INT * SIZEOF_INT);
92
93
0
    DBUG_ASSERT(((ulonglong)(intptr)ptr) >= SIZEOF_INT);
94
0
    if (end_words > ptr)
95
0
    {
96
0
      while (end > end_words && end[-1] == 0x20)
97
0
        end--;
98
0
      if (end[-1] == 0x20 && start_words < end_words)
99
0
        while (end > start_words && ((unsigned *)end)[-1] == SPACE_INT)
100
0
          end -= SIZEOF_INT;
101
0
    }
102
0
  }
103
0
  while (end > ptr && end[-1] == 0x20)
104
0
    end--;
105
0
  return (end);
106
0
}
Unexecuted instantiation: ctype-ucs2.c:skip_trailing_space
Unexecuted instantiation: ctype-utf8.c:skip_trailing_space
Unexecuted instantiation: ctype.c:skip_trailing_space
Unexecuted instantiation: dtoa.c:skip_trailing_space
Unexecuted instantiation: int2str.c:skip_trailing_space
Unexecuted instantiation: ctype-unidata.c:skip_trailing_space
Unexecuted instantiation: xml.c:skip_trailing_space
Unexecuted instantiation: ctype-mb.c:skip_trailing_space
Unexecuted instantiation: ctype-simple.c:skip_trailing_space
Unexecuted instantiation: ctype-uca.c:skip_trailing_space
Unexecuted instantiation: ctype-uca0900.c:skip_trailing_space
Unexecuted instantiation: ctype-uca1400.c:skip_trailing_space
Unexecuted instantiation: my_strtoll10.c:skip_trailing_space
Unexecuted instantiation: my_vsnprintf.c:skip_trailing_space
Unexecuted instantiation: strfill.c:skip_trailing_space
Unexecuted instantiation: strmake.c:skip_trailing_space
Unexecuted instantiation: strnmov.c:skip_trailing_space
Unexecuted instantiation: strxnmov.c:skip_trailing_space
Unexecuted instantiation: ctype-bin.c:skip_trailing_space
Unexecuted instantiation: ctype-latin1.c:skip_trailing_space
Unexecuted instantiation: bchange.c:skip_trailing_space
Unexecuted instantiation: bmove_upp.c:skip_trailing_space
Unexecuted instantiation: ctype-big5.c:skip_trailing_space
Unexecuted instantiation: ctype-cp932.c:skip_trailing_space
Unexecuted instantiation: ctype-czech.c:skip_trailing_space
Unexecuted instantiation: ctype-euc_kr.c:skip_trailing_space
Unexecuted instantiation: ctype-eucjpms.c:skip_trailing_space
Unexecuted instantiation: ctype-extra.c:skip_trailing_space
Unexecuted instantiation: ctype-gb2312.c:skip_trailing_space
Unexecuted instantiation: ctype-gbk.c:skip_trailing_space
Unexecuted instantiation: ctype-sjis.c:skip_trailing_space
Unexecuted instantiation: ctype-tis620.c:skip_trailing_space
Unexecuted instantiation: ctype-ujis.c:skip_trailing_space
Unexecuted instantiation: ctype-win1250ch.c:skip_trailing_space
Unexecuted instantiation: is_prefix.c:skip_trailing_space
Unexecuted instantiation: str2int.c:skip_trailing_space
Unexecuted instantiation: strend.c:skip_trailing_space
Unexecuted instantiation: strxmov.c:skip_trailing_space
Unexecuted instantiation: strmov_overlapp.c:skip_trailing_space
107
108
109
static inline my_strnxfrm_ret_t
110
my_strnxfrm_ret_construct(size_t output_length,
111
                          size_t source_length_used,
112
                          uint warnings)
113
0
{
114
0
  my_strnxfrm_ret_t rc= {output_length,
115
0
                         source_length_used,
116
0
                         warnings};
117
0
  return rc;
118
0
}
Unexecuted instantiation: ctype-ucs2.c:my_strnxfrm_ret_construct
Unexecuted instantiation: ctype-utf8.c:my_strnxfrm_ret_construct
Unexecuted instantiation: ctype.c:my_strnxfrm_ret_construct
Unexecuted instantiation: dtoa.c:my_strnxfrm_ret_construct
Unexecuted instantiation: int2str.c:my_strnxfrm_ret_construct
Unexecuted instantiation: ctype-unidata.c:my_strnxfrm_ret_construct
Unexecuted instantiation: xml.c:my_strnxfrm_ret_construct
Unexecuted instantiation: ctype-mb.c:my_strnxfrm_ret_construct
Unexecuted instantiation: ctype-simple.c:my_strnxfrm_ret_construct
Unexecuted instantiation: ctype-uca.c:my_strnxfrm_ret_construct
Unexecuted instantiation: ctype-uca0900.c:my_strnxfrm_ret_construct
Unexecuted instantiation: ctype-uca1400.c:my_strnxfrm_ret_construct
Unexecuted instantiation: my_strtoll10.c:my_strnxfrm_ret_construct
Unexecuted instantiation: my_vsnprintf.c:my_strnxfrm_ret_construct
Unexecuted instantiation: strfill.c:my_strnxfrm_ret_construct
Unexecuted instantiation: strmake.c:my_strnxfrm_ret_construct
Unexecuted instantiation: strnmov.c:my_strnxfrm_ret_construct
Unexecuted instantiation: strxnmov.c:my_strnxfrm_ret_construct
Unexecuted instantiation: ctype-bin.c:my_strnxfrm_ret_construct
Unexecuted instantiation: ctype-latin1.c:my_strnxfrm_ret_construct
Unexecuted instantiation: bchange.c:my_strnxfrm_ret_construct
Unexecuted instantiation: bmove_upp.c:my_strnxfrm_ret_construct
Unexecuted instantiation: ctype-big5.c:my_strnxfrm_ret_construct
Unexecuted instantiation: ctype-cp932.c:my_strnxfrm_ret_construct
Unexecuted instantiation: ctype-czech.c:my_strnxfrm_ret_construct
Unexecuted instantiation: ctype-euc_kr.c:my_strnxfrm_ret_construct
Unexecuted instantiation: ctype-eucjpms.c:my_strnxfrm_ret_construct
Unexecuted instantiation: ctype-extra.c:my_strnxfrm_ret_construct
Unexecuted instantiation: ctype-gb2312.c:my_strnxfrm_ret_construct
Unexecuted instantiation: ctype-gbk.c:my_strnxfrm_ret_construct
Unexecuted instantiation: ctype-sjis.c:my_strnxfrm_ret_construct
Unexecuted instantiation: ctype-tis620.c:my_strnxfrm_ret_construct
Unexecuted instantiation: ctype-ujis.c:my_strnxfrm_ret_construct
Unexecuted instantiation: ctype-win1250ch.c:my_strnxfrm_ret_construct
Unexecuted instantiation: is_prefix.c:my_strnxfrm_ret_construct
Unexecuted instantiation: str2int.c:my_strnxfrm_ret_construct
Unexecuted instantiation: strend.c:my_strnxfrm_ret_construct
Unexecuted instantiation: strxmov.c:my_strnxfrm_ret_construct
Unexecuted instantiation: strmov_overlapp.c:my_strnxfrm_ret_construct
119
120
121
static inline my_strnxfrm_pad_ret_t
122
my_strnxfrm_pad_ret_construct(size_t output_length,
123
                              uint warnings)
124
0
{
125
0
  my_strnxfrm_pad_ret_t rc= {output_length,
126
0
                             warnings};
127
0
  return rc;
128
0
}
Unexecuted instantiation: ctype-ucs2.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: ctype-utf8.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: ctype.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: dtoa.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: int2str.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: ctype-unidata.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: xml.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: ctype-mb.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: ctype-simple.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: ctype-uca.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: ctype-uca0900.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: ctype-uca1400.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: my_strtoll10.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: my_vsnprintf.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: strfill.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: strmake.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: strnmov.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: strxnmov.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: ctype-bin.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: ctype-latin1.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: bchange.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: bmove_upp.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: ctype-big5.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: ctype-cp932.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: ctype-czech.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: ctype-euc_kr.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: ctype-eucjpms.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: ctype-extra.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: ctype-gb2312.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: ctype-gbk.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: ctype-sjis.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: ctype-tis620.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: ctype-ujis.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: ctype-win1250ch.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: is_prefix.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: str2int.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: strend.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: strxmov.c:my_strnxfrm_pad_ret_construct
Unexecuted instantiation: strmov_overlapp.c:my_strnxfrm_pad_ret_construct
129
130
131
static inline void
132
my_strnxfrm_ret_join_pad(my_strnxfrm_ret_t *rc,
133
                         const my_strnxfrm_pad_ret_t *rcpad)
134
0
{
135
0
  rc->m_result_length+= rcpad->m_result_length;
136
0
  rc->m_warnings|= rcpad->m_warnings;
137
0
}
Unexecuted instantiation: ctype-ucs2.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: ctype-utf8.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: ctype.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: dtoa.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: int2str.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: ctype-unidata.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: xml.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: ctype-mb.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: ctype-simple.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: ctype-uca.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: ctype-uca0900.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: ctype-uca1400.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: my_strtoll10.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: my_vsnprintf.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: strfill.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: strmake.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: strnmov.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: strxnmov.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: ctype-bin.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: ctype-latin1.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: bchange.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: bmove_upp.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: ctype-big5.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: ctype-cp932.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: ctype-czech.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: ctype-euc_kr.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: ctype-eucjpms.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: ctype-extra.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: ctype-gb2312.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: ctype-gbk.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: ctype-sjis.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: ctype-tis620.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: ctype-ujis.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: ctype-win1250ch.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: is_prefix.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: str2int.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: strend.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: strxmov.c:my_strnxfrm_ret_join_pad
Unexecuted instantiation: strmov_overlapp.c:my_strnxfrm_ret_join_pad
138
139
140
int my_strnncollsp_nchars_generic(CHARSET_INFO *cs,
141
                                  const uchar *str1, size_t len1,
142
                                  const uchar *str2, size_t len2,
143
                                  size_t nchars,
144
                                  uint flags);
145
146
int my_strnncollsp_nchars_generic_8bit(CHARSET_INFO *cs,
147
                                       const uchar *str1, size_t len1,
148
                                       const uchar *str2, size_t len2,
149
                                       size_t nchars,
150
                                       uint flags);
151
152
153
size_t  my_strnxfrmlen_simple(CHARSET_INFO *, size_t);
154
155
my_strnxfrm_ret_t
156
my_strnxfrm_simple(CHARSET_INFO *,
157
                   uchar *dst, size_t dstlen, uint nweights,
158
                   const uchar *src, size_t srclen, uint flags);
159
160
161
my_strnxfrm_ret_t
162
my_strnxfrm_mb(CHARSET_INFO *,
163
               uchar *dst, size_t dstlen, uint nweights,
164
               const uchar *src, size_t srclen, uint flags);
165
166
my_strnxfrm_ret_t
167
my_strnxfrm_mb_nopad(CHARSET_INFO *,
168
                    uchar *dst, size_t dstlen, uint nweights,
169
                    const uchar *src, size_t srclen, uint flags);
170
171
size_t  my_strnxfrmlen_unicode(CHARSET_INFO *, size_t);
172
173
size_t  my_strnxfrmlen_unicode_full_bin(CHARSET_INFO *, size_t);
174
175
my_strnxfrm_ret_t
176
my_strnxfrm_unicode_full_bin(CHARSET_INFO *,
177
                             uchar *dst, size_t dstlen, uint nweights,
178
                             const uchar *src, size_t srclen, uint flags);
179
180
my_strnxfrm_ret_t
181
my_strnxfrm_unicode_full_nopad_bin(CHARSET_INFO *,
182
                                   uchar *dst, size_t dstlen, uint nweights,
183
                                   const uchar *src, size_t srclen,
184
                                   uint flags);
185
186
my_strnxfrm_ret_t
187
my_strxfrm_pad_desc_and_reverse(CHARSET_INFO *cs,
188
                                uchar *str, uchar *frmend, uchar *strend,
189
                                uint nweights, uint flags, uint level);
190
191
my_strnxfrm_ret_t
192
my_strxfrm_pad_desc_and_reverse_nopad(CHARSET_INFO *cs,
193
                                      uchar *str, uchar *frmend,
194
                                      uchar *strend, uint nweights,
195
                                      uint flags, uint level);
196
197
uint my_8bit_charset_flags_from_data(CHARSET_INFO *cs);
198
uint my_8bit_collation_flags_from_data(CHARSET_INFO *cs);
199
200
201
/* Macros for hashing characters */
202
203
#define MY_HASH_ADD(A, B, value) \
204
0
  do { A^= (((A & 63)+B)*((value)))+ (A << 8); B+=3; } while(0)
205
206
#define MY_HASH_ADD_16(A, B, value) \
207
0
  do { MY_HASH_ADD(A, B, ((value) & 0xFF)) ; MY_HASH_ADD(A, B, ((value >>8 ))); } while(0) 
208
209
210
0
#define my_wc_t ulong
211
212
int my_wc_to_printable_ex(CHARSET_INFO *cs, my_wc_t wc,
213
                          uchar *s, uchar *e,
214
                          uint bs, uint bslen, uint diglen);
215
216
int my_wc_to_printable_generic(CHARSET_INFO *cs, my_wc_t wc,
217
                               uchar *s, uchar *e);
218
219
int my_wc_to_printable_8bit(CHARSET_INFO *cs, my_wc_t wc,
220
                            uchar *s, uchar *e);
221
222
void my_ci_set_strength(struct charset_info_st *cs, uint strength);
223
void my_ci_set_level_flags(struct charset_info_st *cs, uint flags);
224
225
uint my_casefold_multiply_1(CHARSET_INFO *cs);
226
uint my_casefold_multiply_2(CHARSET_INFO *cs);
227
228
my_bool my_ci_eq_collation_generic(CHARSET_INFO *self, CHARSET_INFO *other);
229
230
struct charset_info_st *my_ci_alloc(MY_CHARSET_LOADER *loader,
231
                                    const LEX_CSTRING name,
232
                                    LEX_CSTRING *out_name,
233
                                    const LEX_CSTRING comment,
234
                                    LEX_CSTRING *out_comment);
235
236
/* Some common character set names */
237
extern const char charset_name_latin2[];
238
#define charset_name_latin2_length 6
239
extern const char charset_name_utf8mb3[];
240
#define charset_name_utf8mb3_length 7
241
extern const char charset_name_utf16[];
242
#define charset_name_utf16_length 5
243
extern const char charset_name_utf32[];
244
#define charset_name_utf32_length 5
245
extern const char charset_name_ucs2[];
246
#define charset_name_ucs2_length 4
247
extern const char charset_name_utf8mb4[];
248
#define charset_name_utf8mb4_length 7
249
250
#endif /*STRINGS_DEF_INCLUDED */