1 /* Copyright (c) 2016, 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 #include "xpl_regex.h"
24
25 #include "my_dbug.h"
26 #include <cstring>
27
28
29 namespace
30 {
31
check_result(const int err)32 inline void check_result(const int err)
33 {
34 assert( err == 0 );
35 }
36
37
38 const struct Regex_finalizer
39 {
Regex_finalizer__anonae546b1f0111::Regex_finalizer40 Regex_finalizer() {}
~Regex_finalizer__anonae546b1f0111::Regex_finalizer41 ~Regex_finalizer() { my_regex_end(); }
42 } regex_finalizer;
43
44 } // namespace
45
46
Regex(const char * const pattern)47 xpl::Regex::Regex(const char* const pattern)
48 {
49 memset(&m_re, 0, sizeof(m_re));
50 int err = my_regcomp(&m_re, pattern,
51 (MY_REG_EXTENDED | MY_REG_ICASE | MY_REG_NOSUB),
52 &my_charset_latin1);
53
54 // Workaround for unused variable
55 check_result(err);
56 }
57
58
~Regex()59 xpl::Regex::~Regex()
60 {
61 my_regfree(&m_re);
62 }
63
64
match(const char * value) const65 bool xpl::Regex::match(const char *value) const
66 {
67 return my_regexec(&m_re, value, (size_t)0, NULL, 0) == 0;
68 }
69
70