monotone

monotone Mtn Source Tree

Root/globish.hh

1#ifndef __GLOBISH_HH__
2#define __GLOBISH_HH__
3
4// Copyright (C) 2005 Nathaniel Smith <njs@pobox.com>
5//
6// This program is made available under the GNU GPL version 2.0 or
7// greater. See the accompanying file COPYING for details.
8//
9// This program is distributed WITHOUT ANY WARRANTY; without even the
10// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11// PURPOSE.
12
13// a sort of glob-like pattern matcher, for use in specifying branch
14// collections for netsync. it is important that it not be too expensive to
15// match (as opposed to common regex engines, which can be exponential on
16// pathological patterns), because we must match branches against untrusted
17// patterns when doing netsync.
18
19// the syntax is:
20// most things - match themselves
21// * - match 0 or more characters
22// ? - match 0 or 1 characters
23// \<any character> - match <any character>
24// {<anything1>,<anything2>,...} - match any of the given items
25// so like standard globs, except without [] character sets, and with {}
26// alternation.
27// the one strange thing is there is a special-case -- the empty pattern
28// matches nothing, not even the empty string. this hardly ever matters, but
29// it's nice to have some way to say "don't exclude anything", for instance.
30
31#include <set>
32#include <string>
33#include <boost/regex.hpp>
34
35#include "vocab.hh"
36
37void combine_and_check_globish(std::vector<globish> const &patterns,
38 globish & pattern);
39
40class globish_matcher
41{
42public:
43 // this may throw an informative_failure if a pattern is invalid
44 globish_matcher(globish const & include_pat, globish const & exclude_pat);
45 // this method may throw a std::runtime_error if the pattern is really
46 // pathological
47 bool operator()(std::string const & s);
48private:
49 boost::regex r_inc, r_exc;
50};
51
52// Local Variables:
53// mode: C++
54// fill-column: 76
55// c-file-style: "gnu"
56// indent-tabs-mode: nil
57// End:
58// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
59
60#endif

Archive Download this file

Branches

Tags

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