]> git.lyx.org Git - lyx.git/blob - src/support/LRegex.h
Small things in my tree.
[lyx.git] / src / support / LRegex.h
1 // -*- C++ -*-
2
3 /* C++ wrapper around the POSIX regex functions:
4    regcomp, regexec, regerror, regfree.
5 */
6
7 #ifndef LREGEX_H
8 #define LREGEX_H
9
10 #ifdef __GNUG__
11 #pragma interface
12 #endif
13
14 #include "LString.h"
15
16 #include <vector>
17
18 ///
19 class LRegex {
20 public:
21         ///
22         explicit
23         LRegex(string const & regex);
24
25         ///
26         ~LRegex();
27
28         ///
29         typedef std::pair<string::size_type, string::size_type> MatchPair;
30
31         ///
32         typedef std::vector<MatchPair> SubMatches;
33
34         /// Returns all the matches in a vector
35         SubMatches const & exec(string const & str) const;
36
37         /// The whole of str matches regex.
38         bool exact_match(string const & str) const;
39
40         ///
41         MatchPair first_match(string const & str) const;
42
43         ///
44         string getError() const;
45
46         ///
47         int getErrorCode() const;
48
49         /// Will the next operation fail of not.
50         bool ok() const;
51 private:
52         ///
53         struct Impl;
54
55         ///
56         Impl * impl;
57 };
58
59
60 // We comment out these, we can comment them in when we need them.
61 #if 0
62 // some built in regular expressions
63
64 extern const LRegex LRXwhite;          // = "[ \n\t\r\v\f]+"
65 extern const LRegex LRXint;            // = "-?[0-9]+"
66 extern const LRegex LRXdouble;         // = "-?\\(\\([0-9]+\\.[0-9]*\\)\\|
67                                        //    \\([0-9]+\\)\\|\\(\\.[0-9]+\\)\\)
68                                        //    \\([eE][---+]?[0-9]+\\)?"
69 //extern const LRegex LRXalpha;          // = "[A-Za-z]+"
70 //extern const LRegex LRXlowercase;      // = "[a-z]+"
71 //extern const LRegex LRXuppercase;      // = "[A-Z]+"
72 //extern const LRegex LRXalphanum;       // = "[0-9A-Za-z]+"
73 extern const LRegex LRXidentifier;     // = "[A-Za-z_][A-Za-z0-9_]*"
74 #endif
75 #endif