monotone

monotone Mtn Source Tree

Root/pcrewrap.hh

1// Copyright (C) 2007 Zack Weinberg <zackw@panix.com>
2//
3// This program is made available under the GNU GPL version 2.0 or
4// greater. See the accompanying file COPYING for details.
5//
6// This program is distributed WITHOUT ANY WARRANTY; without even the
7// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8// PURPOSE.
9
10#ifndef _PCREWRAP_HH
11#define _PCREWRAP_HH
12
13// This is a sensible C++ wrapper interface around the bare C API exported
14// by pcre.h. Note that pcre.h is a very "noisy" header in terms of macro
15// definitions and so we don't actually expose it here. Unfortunately, this
16// means we have to hope this pair of forward declarations will not change...
17
18struct real_pcre;
19struct pcre_extra;
20
21namespace pcre
22{
23 enum flags
24 {
25 // flags usable with both pcre_compile and pcre_exec
26 DEFAULT = 0x0000, // no special behavior
27 NEWLINE_CR = 0x0001, // newline is \r
28 NEWLINE_LF = 0x0002, // newline is \n
29 NEWLINE_CRLF = (NEWLINE_CR|NEWLINE_LF), // newline is \r\n
30 ANCHORED = 0x0004, // match only at beginning
31 // of string (\A in pat)
32 // flags usable only with pcre_exec
33 NOTBOL = 0x0008, // beginning of string isn't beginning of line
34 NOTEOL = 0x0010, // end of string isn't end of line
35 NOTEMPTY = 0x0020, // an empty match is a match failure
36
37 // flags usable only with pcre_compile
38 CASELESS = 0x0040, // case insensitive match (?i)
39 DOLLAR_ENDONLY = 0x0080, // only in !MULTILINE mode, $ equiv to \Z
40 DOTALL = 0x0100, // dot matches newline (?s)
41 DUPNAMES = 0x0200, // permit duplicate names for named captures
42 EXTENDED = 0x0400, // whitespace permitted in syntax (?x)
43 FIRSTLINE = 0x0800, // match must begin before first newline
44 MULTILINE = 0x1000, // ^ and $ match at internal newlines (?m)
45 UNGREEDY = 0x4000, // quantifiers aren't greedy unless
46 // followed with ? (opposite of default)
47 };
48
49 // A regex object is the compiled form of a PCRE regular expression.
50 struct regex
51 {
52 private:
53 // disable the default and copy constructors - we never need to copy
54 // these, and this lets us use bare pointers below instead of
55 // boost::shared_ptr.
56 regex();
57 regex(regex const &);
58 regex & operator=(regex const &);
59
60 // data
61 struct real_pcre const * basedat;
62 struct pcre_extra const * extradat;
63
64 // used by constructors
65 void init(char const *, pcre::flags);
66
67 public:
68 regex(char const * pattern, pcre::flags options = DEFAULT);
69 regex(std::string const & pattern, pcre::flags options = DEFAULT);
70 ~regex();
71
72 bool match(std::string const & subject,
73 pcre::flags options = DEFAULT) const;
74 };
75} // namespace pcre
76
77#endif // pcrewrap.hh
78
79// Local Variables:
80// mode: C++
81// fill-column: 76
82// c-file-style: "gnu"
83// indent-tabs-mode: nil
84// End:
85// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status