1 /* Copyright (c) 2006, 2021, Oracle and/or its affiliates.
2 
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License, version 2.0,
5    as published by the Free Software Foundation.
6 
7    This program is also distributed with certain software (including
8    but not limited to OpenSSL) that is licensed under separate terms,
9    as designated in a particular file or component or in included license
10    documentation.  The authors of MySQL hereby grant you an additional
11    permission to link the program and your derivative works with the
12    separately licensed software that they have included with MySQL.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License, version 2.0, for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
22 
23 #ifndef STRFUNC_INCLUDED
24 #define STRFUNC_INCLUDED
25 
26 #include "my_global.h"                          /* ulonglong, uint */
27 
28 typedef struct charset_info_st CHARSET_INFO;
29 typedef struct st_mysql_lex_string LEX_STRING;
30 typedef struct st_typelib TYPELIB;
31 class THD;
32 
33 ulonglong find_set(TYPELIB *lib, const char *x, size_t length,
34                    const CHARSET_INFO *cs,
35 		   char **err_pos, uint *err_len, bool *set_warning);
36 ulonglong find_set_from_flags(TYPELIB *lib, uint default_name,
37                               ulonglong cur_set, ulonglong default_set,
38                               const char *str, uint length,
39                               const CHARSET_INFO *cs,
40                               char **err_pos, uint *err_len, bool *set_warning);
41 uint find_type(const TYPELIB *lib, const char *find, size_t length,
42                bool part_match);
43 uint find_type2(const TYPELIB *lib, const char *find, size_t length,
44                 const CHARSET_INFO *cs);
45 void unhex_type2(TYPELIB *lib);
46 uint check_word(TYPELIB *lib, const char *val, const char *end,
47 		const char **end_of_word);
48 int find_string_in_array(LEX_STRING * const haystack, LEX_STRING * const needle,
49                          CHARSET_INFO * const cs);
50 char *flagset_to_string(THD *thd, LEX_STRING *result, ulonglong set,
51                         const char *lib[]);
52 char *set_to_string(THD *thd, LEX_STRING *result, ulonglong set,
53                     const char *lib[]);
54 
55 /*
56   These functions were protected by INNODB_COMPATIBILITY_HOOKS
57  */
58 size_t strconvert(CHARSET_INFO *from_cs, const char *from,
59                   CHARSET_INFO *to_cs, char *to, size_t to_length, uint *errors);
60 
61 
62 /**
63   convert a hex digit into number.
64 */
65 
hexchar_to_int(char c)66 inline int hexchar_to_int(char c)
67 {
68   if (c <= '9' && c >= '0')
69     return c-'0';
70   c|=32;
71   if (c <= 'f' && c >= 'a')
72     return c-'a'+10;
73   return -1;
74 }
75 
76 #endif /* STRFUNC_INCLUDED */
77