MySQL  8.0.19
Source Code Documentation
pattern_matcher.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
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, version 2.0,
6  as published by the Free Software Foundation.
7 
8  This program is also distributed with certain software (including
9  but not limited to OpenSSL) that is licensed under separate terms,
10  as designated in a particular file or component or in included license
11  documentation. The authors of MySQL hereby grant you an additional
12  permission to link the program and your derivative works with the
13  separately licensed software that they have included with MySQL.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License, version 2.0, for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24 
25 #include <m_ctype.h>
26 #include <string>
27 #include <unordered_set>
28 
29 /**
30  Enables comparison of strings against particular set of patterns. Patterns
31  may contain wildcards (WILD_ONE/WILD_MANY/WILD_ESCAPE). Pattern strings may
32  be added to the class through a special method. Matching method traverses all
33  of the patterns within pattern matcher in search for a match.
34 */
36  public:
37  size_t add_patterns(const std::string &patterns, char delimiter = ':');
38  bool is_matching(const std::string &text, const CHARSET_INFO *info) const;
39  void clear();
40 
41  private:
42  /** any (single) character wild card */
43  const static char WILD_ONE = '?';
44 
45  /** zero or many characters wild card */
46  const static char WILD_MANY = '*';
47 
48  /** escape sequence character */
49  const static char WILD_ESCAPE = '\\';
50 
51  /** used for storing matcher patterns */
52  std::unordered_set<std::string> m_patterns;
53 };
Pattern_matcher::WILD_ONE
const static char WILD_ONE
any (single) character wild card
Definition: pattern_matcher.h:43
CHARSET_INFO
Definition: m_ctype.h:354
Pattern_matcher::add_patterns
size_t add_patterns(const std::string &patterns, char delimiter=':')
Parses concatenated patterns and adds them to internal pattern list.
Definition: pattern_matcher.cc:38
Pattern_matcher::WILD_MANY
const static char WILD_MANY
zero or many characters wild card
Definition: pattern_matcher.h:46
Pattern_matcher::WILD_ESCAPE
const static char WILD_ESCAPE
escape sequence character
Definition: pattern_matcher.h:49
delimiter
const char * delimiter
Definition: mysqlslap.cc:154
Pattern_matcher::clear
void clear()
Removes all previously stored patterns from pattern matcher.
Definition: pattern_matcher.cc:95
m_ctype.h
Pattern_matcher::is_matching
bool is_matching(const std::string &text, const CHARSET_INFO *info) const
Verifies whether text matches any of the matcher internal patterns.
Definition: pattern_matcher.cc:76
Pattern_matcher
Enables comparison of strings against particular set of patterns.
Definition: pattern_matcher.h:35
info
Log info(cout, "NOTE")
Pattern_matcher::m_patterns
std::unordered_set< std::string > m_patterns
used for storing matcher patterns
Definition: pattern_matcher.h:52