diff options
Diffstat (limited to 'src/RegExp.cc')
-rw-r--r-- | src/RegExp.cc | 109 |
1 files changed, 0 insertions, 109 deletions
diff --git a/src/RegExp.cc b/src/RegExp.cc deleted file mode 100644 index 895cc7b..0000000 --- a/src/RegExp.cc +++ /dev/null | |||
@@ -1,109 +0,0 @@ | |||
1 | // RegExp.cc for Fluxbox Window Manager | ||
2 | // Copyright (c) 2003 Henrik Kinnunen (fluxgen at fluxbox dot org) | ||
3 | // and Simon Bowden (rathnor at users.sourceforge.net) | ||
4 | // | ||
5 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
6 | // copy of this software and associated documentation files (the "Software"), | ||
7 | // to deal in the Software without restriction, including without limitation | ||
8 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
9 | // and/or sell copies of the Software, and to permit persons to whom the | ||
10 | // Software is furnished to do so, subject to the following conditions: | ||
11 | // | ||
12 | // The above copyright notice and this permission notice shall be included in | ||
13 | // all copies or substantial portions of the Software. | ||
14 | // | ||
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
21 | // DEALINGS IN THE SOFTWARE. | ||
22 | |||
23 | // $Id$ | ||
24 | |||
25 | #include "RegExp.hh" | ||
26 | #include "FbTk/I18n.hh" | ||
27 | |||
28 | //use GNU extensions | ||
29 | #ifndef _GNU_SOURCE | ||
30 | #define _GNU_SOURCE | ||
31 | #endif // _GNU_SOURCE | ||
32 | |||
33 | #include <string> | ||
34 | #include <iostream> | ||
35 | |||
36 | using std::string; | ||
37 | |||
38 | #ifdef USE_REGEXP | ||
39 | using std::cerr; | ||
40 | using std::endl; | ||
41 | #endif // USE_REGEXP | ||
42 | |||
43 | |||
44 | /******************************************************** | ||
45 | * RegExp * | ||
46 | **********/ | ||
47 | |||
48 | // full_match is to say if we match on this regexp using the full string | ||
49 | // or just a substring. Substrings aren't supported if not HAVE_REGEXP | ||
50 | RegExp::RegExp(const string &str, bool full_match): | ||
51 | #ifdef USE_REGEXP | ||
52 | m_regex(0) { | ||
53 | string match; | ||
54 | if (full_match) { | ||
55 | match = "^"; | ||
56 | match.append(str); | ||
57 | match.append("$"); | ||
58 | } else { | ||
59 | match = str; | ||
60 | } | ||
61 | |||
62 | m_regex = new regex_t; | ||
63 | int ret = regcomp(m_regex, match.c_str(), REG_NOSUB | REG_EXTENDED); | ||
64 | if (ret != 0) { | ||
65 | char *errstr = 0; | ||
66 | _FB_USES_NLS; | ||
67 | // gives us the length of the string | ||
68 | unsigned int size = regerror(ret, m_regex, errstr, 0); | ||
69 | errstr = new char[size]; | ||
70 | |||
71 | regerror(ret, m_regex, errstr, size); | ||
72 | cerr<<_FB_CONSOLETEXT(Fluxbox, ErrorRegexp, "Error parsing regular expression", "Error parsing regular expression (following)")<<": "<<errstr<<endl; | ||
73 | delete [] errstr; | ||
74 | delete m_regex; // I don't think I regfree a failed compile? | ||
75 | m_regex = 0; | ||
76 | } | ||
77 | } | ||
78 | #else // notdef USE_REGEXP | ||
79 | m_str(str) {} | ||
80 | #endif // USE_REGEXP | ||
81 | |||
82 | RegExp::~RegExp() { | ||
83 | #ifdef USE_REGEXP | ||
84 | if (m_regex != 0) { | ||
85 | regfree(m_regex); | ||
86 | delete m_regex; | ||
87 | } | ||
88 | #endif // USE_REGEXP | ||
89 | } | ||
90 | |||
91 | bool RegExp::match(const string &str) const { | ||
92 | #ifdef USE_REGEXP | ||
93 | if (m_regex) | ||
94 | return regexec(m_regex, str.c_str(), 0, 0, 0) == 0; | ||
95 | else | ||
96 | return false; | ||
97 | #else // notdef USE_REGEXP | ||
98 | return (m_str == str); | ||
99 | #endif // USE_REGEXP | ||
100 | } | ||
101 | |||
102 | |||
103 | bool RegExp::error() const { | ||
104 | #ifdef USE_REGEXP | ||
105 | return m_regex == 0; | ||
106 | #else | ||
107 | return m_str == ""; | ||
108 | #endif // USE_REGEXP | ||
109 | } | ||