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#include "sanity.hh"
14#include <vector>
15
16// This is a sensible C++ wrapper interface around the bare C API exported
17// by pcre.h. Note that pcre.h is a very "noisy" header in terms of macro
18// definitions and so we don't actually expose it here. Unfortunately, this
19// means we have to hope this pair of forward declarations will not change...
20
21struct real_pcre;
22struct pcre_extra;
23
24namespace pcre
25{
26 enum flags
27 {
28 // flags usable with both pcre_compile and pcre_exec
29 DEFAULT = 0x0000, // no special behavior
30 NEWLINE_CR = 0x0001, // newline is \r
31 NEWLINE_LF = 0x0002, // newline is \n
32 NEWLINE_CRLF = (NEWLINE_CR|NEWLINE_LF), // newline is \r\n
33 ANCHORED = 0x0004, // match only at beginning
34 // of string (\A in pat)
35 // flags usable only with pcre_exec
36 NOTBOL = 0x0008, // beginning of string isn't beginning of line
37 NOTEOL = 0x0010, // end of string isn't end of line
38 NOTEMPTY = 0x0020, // an empty match is a match failure
39
40 // flags usable only with pcre_compile
41 CASELESS = 0x0040, // case insensitive match (?i)
42 DOLLAR_ENDONLY = 0x0080, // only in !MULTILINE mode, $ equiv to \Z
43 DOTALL = 0x0100, // dot matches newline (?s)
44 DUPNAMES = 0x0200, // permit duplicate names for named captures
45 EXTENDED = 0x0400, // whitespace permitted in syntax (?x)
46 FIRSTLINE = 0x0800, // match must begin before first newline
47 MULTILINE = 0x1000, // ^ and $ match at internal newlines (?m)
48 UNGREEDY = 0x4000, // quantifiers aren't greedy unless
49 // followed with ? (opposite of default)
50 };
51
52 // A regex object is the compiled form of a PCRE regular expression.
53 struct regex
54 {
55 private:
56 // disable the default and copy constructors - we never need to copy
57 // these, and this lets us use bare pointers below instead of
58 // boost::shared_ptr.
59 regex();
60 regex(regex const &);
61 regex & operator=(regex const &);
62
63 // data
64 struct real_pcre const * basedat;
65 struct pcre_extra const * extradat;
66
67 // used by constructors
68 void init(char const *, pcre::flags);
69
70 origin::type made_from;
71 public:
72 regex(char const * pattern, origin::type whence,
73 pcre::flags options = DEFAULT);
74 regex(std::string const & pattern, origin::type whence,
75 pcre::flags options = DEFAULT);
76 ~regex();
77
78 bool match(std::string const & subject, origin::type subject_origin,
79 pcre::flags options = DEFAULT) const;
80
81 bool match(std::string const & subject, origin::type subject_origin,
82 std::vector<std::string> & matches, pcre::flags options = DEFAULT) const;
83 };
84} // namespace pcre
85
86#endif // pcrewrap.hh
87
88// Local Variables:
89// mode: C++
90// fill-column: 76
91// c-file-style: "gnu"
92// indent-tabs-mode: nil
93// End:
94// 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