libt3widget
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups
findcontext.h
1 /* Copyright (C) 2011-2012 G.P. Halkes
2  This program is free software: you can redistribute it and/or modify
3  it under the terms of the GNU General Public License version 3, as
4  published by the Free Software Foundation.
5 
6  This program is distributed in the hope that it will be useful,
7  but WITHOUT ANY WARRANTY; without even the implied warranty of
8  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  GNU General Public License for more details.
10 
11  You should have received a copy of the GNU General Public License
12  along with this program. If not, see <http://www.gnu.org/licenses/>.
13 */
14 #ifndef T3_WIDGET_FINDCONTEXT_H
15 #define T3_WIDGET_FINDCONTEXT_H
16 
17 #include <string>
18 #include <pcre.h>
19 
20 #include <t3widget/widget_api.h>
21 #include <t3widget/stringmatcher.h>
22 #include <t3widget/util.h>
23 
24 namespace t3_widget {
25 
30 struct T3_WIDGET_API find_result_t {
31  text_coordinate_t start, end;
32 };
33 
35 class T3_WIDGET_API finder_t {
36  private:
37  static void call_pcre_free(pcre *);
38 
40  int flags;
41 
43  cleanup_ptr<string_matcher_t>::t matcher;
44 
45  /* PCRE context and data */
47  cleanup_func_ptr<pcre, call_pcre_free>::t regex;
49  int ovector[30];
51  int captures;
52  bool found;
55  cleanup_ptr<std::string>::t replacement;
56 
58  cleanup_free_ptr<char>::t folded;
60  size_t folded_size;
61 
63  static int adjust_position(const std::string *str, int pos, int adjust);
69  bool check_boundaries(const std::string *str, int match_start, int match_end);
70 
71  public:
73  finder_t(void);
78  finder_t(const std::string *needle, int flags, const std::string *replacement = NULL);
80  virtual ~finder_t(void);
86  finder_t &operator=(finder_t& other);
87 
92  void set_context(const std::string *needle, int flags, const std::string *replacement = NULL);
94  bool match(const std::string *haystack, find_result_t *result, bool reverse);
96  int get_flags(void);
101  std::string *get_replacement(const std::string *haystack);
102 };
103 
104 }; // namespace
105 #endif
A struct holding the result of a find operation.
Definition: findcontext.h:30
Class holding the context of a find operation.
Definition: findcontext.h:35
Definition: util.h:49