ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/truck/Common/regex.hpp
Revision: 14
Committed: 2007-05-14T18:24:34-07:00 (15 years, 6 months ago) by douglas
File size: 2411 byte(s)
Log Message:
Switch back from Menes C++ to stl and hacks.

File Contents

# Content
1 // Charlemagne Package Manager
2 //
3 // Douglas Thrift
4 //
5 // $Id$
6
7 /* Menes - C++ High-Level Utility Library
8 * Copyright (C) 2003-2005 Jay Freeman (saurik)
9 */
10
11 /*
12 * Redistribution and use in source and binary
13 * forms, with or without modification, are permitted
14 * provided that the following conditions are met:
15 *
16 * 1. Redistributions of source code must retain the
17 * above copyright notice, this list of conditions
18 * and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the
20 * above copyright notice, this list of conditions
21 * and the following disclaimer in the documentation
22 * and/or other materials provided with the
23 * distribution.
24 * 3. The name of the author may not be used to endorse
25 * or promote products derived from this software
26 * without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
30 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
31 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
33 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
34 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
35 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
36 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
38 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
39 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
40 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 */
43
44 #ifndef _regex_hpp_
45 #define _regex_hpp_
46
47 #include <exception>
48 #include <string>
49 #include <vector>
50
51 #include <pcre.h>
52
53 namespace Pcre
54 {
55
56 class Error : public std::exception
57 {
58 std::string message;
59 public:
60 Error(int code);
61 virtual ~Error() throw() {}
62 virtual const char *what() const throw() { return message.c_str(); }
63 };
64
65 class RegEx
66 {
67 public:
68 class Match
69 {
70 friend class RegEx;
71
72 std::string data;
73 std::vector<int> substrings;
74
75 Match(const std::string &data, std::vector<int> &substrings);
76
77 public:
78 Match();
79
80 operator bool() const;
81 std::string operator [](size_t substring) const;
82 };
83
84 private:
85 ::pcre *code;
86 ::pcre_extra *study;
87 int capture;
88
89 public:
90 RegEx(const std::string &pattern);
91 ~RegEx();
92
93 Match operator ()(const std::string &data) const;
94 };
95
96 }
97
98 #endif//_regex_hpp_

Properties

Name Value
svn:keywords Id