blocxx
PerlRegEx.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) 2005 Novell, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * - Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 *
10 * - Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * - Neither the name of Vintela, Inc., Novell, Inc., nor the names of its
15 * contributors may be used to endorse or promote products derived from this
16 * software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc., Novell, Inc., OR THE
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *******************************************************************************/
34 #ifndef BLOCXX_PERL_REGEX_HPP_INCLUDE_GUARD_HPP_
35 #define BLOCXX_PERL_REGEX_HPP_INCLUDE_GUARD_HPP_
36 #include "blocxx/BLOCXX_config.h"
38 
39 #ifdef BLOCXX_HAVE_PCRE
40 #include "blocxx/String.hpp"
41 #include "blocxx/Array.hpp"
42 
43 #ifdef BLOCXX_HAVE_PCRE_H
44 #include <pcre.h>
45 
46 namespace BLOCXX_NAMESPACE
47 {
48 
59 class BLOCXX_COMMON_API PerlRegEx
60 {
61 public:
67  typedef blocxx::Array<int> MatchVector;
68 
70  struct match_t {
71  int rm_so;
72  int rm_eo;
73  };
74 
76  typedef blocxx::Array<match_t> MatchArray;
77 
81  PerlRegEx();
82 
90  PerlRegEx(const String &regex, int cflags = 0);
91 
100  PerlRegEx(const PerlRegEx &ref);
101 
105  ~PerlRegEx();
106 
114  PerlRegEx& operator = (const PerlRegEx &ref);
115 
145  bool compile(const String &regex,
146  int cflags = 0);
147 
161  int errorCode();
162 
169  String errorString() const;
170 
174  String patternString() const;
175 
179  int compileFlags() const;
180 
184  bool isCompiled() const;
185 
272  bool execute(MatchVector &sub,
273  const String &str,
274  size_t index = 0,
275  size_t count = 0,
276  int eflags = 0);
277  bool execute(MatchArray &sub,
278  const String &str,
279  size_t index = 0,
280  size_t count = 0,
281  int eflags = 0);
282  /* @} */
283 
309  StringArray capture(const String &str,
310  size_t index = 0,
311  size_t count = 0,
312  int eflags = 0);
313 
348  String replace(const String &str,
349  const String &rep,
350  bool global = false,
351  int eflags = 0);
352 
383  StringArray split (const String &str,
384  bool empty = false,
385  int eflags = 0);
386 
412  StringArray grep (const StringArray &src,
413  int eflags = 0);
414 
440  bool match (const String &str,
441  size_t index = 0,
442  int eflags = 0) const;
443 
444 private:
445  pcre *m_pcre;
446  int m_flags;
447  mutable int m_ecode;
448  mutable String m_error;
449  String m_rxstr;
450 };
451 
452 } // End of BLOCXX_NAMESPACE
453 
454 #endif // BLOCXX_HAVE_PCRE_H
455 #endif // BLOCXX_HAVE_PCRE
456 
457 #endif // BLOCXX_PERL_REGEX_HPP_INCLUDE_GUARD_HPP_
458 /* vim: set ts=8 sts=8 sw=8 ai noet: */
459