1/*
2 Copyright (c) 2018, MariaDB Corporation.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
17
18#ifndef LEX_STRING_INCLUDED
19#define LEX_STRING_INCLUDED
20
21typedef struct st_mysql_const_lex_string LEX_CSTRING;
22
23/* Functions to compare if two lex strings are equal */
24
25static inline bool lex_string_cmp(CHARSET_INFO *charset, const LEX_CSTRING *a,
26 const LEX_CSTRING *b)
27{
28 return my_strcasecmp(charset, a->str, b->str);
29}
30
31/*
32 Compare to LEX_CSTRING's and return 0 if equal
33*/
34
35static inline bool cmp(const LEX_CSTRING *a, const LEX_CSTRING *b)
36{
37 return (a->length != b->length ||
38 memcmp(a->str, b->str, a->length));
39}
40
41/*
42 Compare if two LEX_CSTRING are equal. Assumption is that
43 character set is ASCII (like for plugin names)
44*/
45
46static inline bool lex_string_eq(const LEX_CSTRING *a, const LEX_CSTRING *b)
47{
48 if (a->length != b->length)
49 return 0; /* Different */
50 return strcasecmp(a->str, b->str) == 0;
51}
52
53/*
54 To be used when calling lex_string_eq with STRING_WITH_LEN() as second
55 argument
56*/
57
58static inline bool lex_string_eq(const LEX_CSTRING *a, const char *b, size_t b_length)
59{
60 if (a->length != b_length)
61 return 0; /* Different */
62 return strcasecmp(a->str, b) == 0;
63}
64
65#endif /* LEX_STRING_INCLUDED */
66