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// all rights reserved.
6// licensed to the public under the terms of the GNU GPL (>= 2)
7// see the file COPYING for details
8
9// a sort of glob-like pattern matcher, for use in specifying branch
10// collections for netsync. it is important that it not be too expensive to
11// match (as opposed to common regex engines, which can be exponential on
12// pathological patterns), because we must match branches against untrusted
13// patterns when doing netsync.
14
15// the syntax is:
16// most things - match themselves
17// * - match 0 or more characters
18// ? - match 0 or 1 characters
19// \<any character> - match <any character>
20// {<anything1>,<anything2>,...} - match any of the given items
21// so like standard globs, except without [] character sets, and with {}
22// alternation.
23// the one strange thing is there is a special-case -- the empty pattern
24// matches nothing, not even the empty string. this hardly ever matters, but
25// it's nice to have some way to say "don't exclude anything", for instance.
26
27#include <set>
28#include <string>
29#include <boost/regex.hpp>
30
31#include "vocab.hh"
32
33void combine_and_check_globish(std::set<utf8> const &patterns, utf8 & pattern);
34
35class globish_matcher
36{
37public:
38 // this may throw an informative_failure if a pattern is invalid
39 globish_matcher(utf8 const & include_pat, utf8 const & exclude_pat);
40 // this method may throw a std::runtime_error if the pattern is really
41 // pathological
42 bool operator()(std::string const & s);
43private:
44 boost::regex r_inc, r_exc;
45};
46
47#endif

Archive Download this file

Branches

Tags

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