summaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/Makefile.am1
-rw-r--r--src/FbTk/RegExp.cc96
-rw-r--r--src/FbTk/RegExp.hh66
3 files changed, 163 insertions, 0 deletions
diff --git a/src/FbTk/Makefile.am b/src/FbTk/Makefile.am
index 86f8594..5f1c246 100644
--- a/src/FbTk/Makefile.am
+++ b/src/FbTk/Makefile.am
@@ -41,6 +41,7 @@ libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \
41 XLayer.cc XLayer.hh XLayerItem.cc XLayerItem.hh \ 41 XLayer.cc XLayer.hh XLayerItem.cc XLayerItem.hh \
42 Resource.hh Resource.cc \ 42 Resource.hh Resource.cc \
43 StringUtil.hh StringUtil.cc Parser.hh Parser.cc \ 43 StringUtil.hh StringUtil.cc Parser.hh Parser.cc \
44 RegExp.hh RegExp.cc \
44 FbString.hh FbString.cc \ 45 FbString.hh FbString.cc \
45 Subject.hh Subject.cc Observer.hh Observer.cc \ 46 Subject.hh Subject.cc Observer.hh Observer.cc \
46 Transparent.hh Transparent.cc \ 47 Transparent.hh Transparent.cc \
diff --git a/src/FbTk/RegExp.cc b/src/FbTk/RegExp.cc
new file mode 100644
index 0000000..df98982
--- /dev/null
+++ b/src/FbTk/RegExp.cc
@@ -0,0 +1,96 @@
1// RegExp.cc for FbTk
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#include "RegExp.hh"
24
25//use GNU extensions
26#ifndef _GNU_SOURCE
27#define _GNU_SOURCE
28#endif // _GNU_SOURCE
29
30#include <string>
31#include <iostream>
32
33using std::string;
34
35#ifdef USE_REGEXP
36using std::cerr;
37using std::endl;
38#endif // USE_REGEXP
39
40namespace FbTk {
41
42// full_match is to say if we match on this regexp using the full string
43// or just a substring. Substrings aren't supported if not HAVE_REGEXP
44RegExp::RegExp(const string &str, bool full_match):
45#ifdef USE_REGEXP
46m_regex(0) {
47 string match;
48 if (full_match) {
49 match = "^";
50 match.append(str);
51 match.append("$");
52 } else {
53 match = str;
54 }
55
56 m_regex = new regex_t;
57 int ret = regcomp(m_regex, match.c_str(), REG_NOSUB | REG_EXTENDED);
58 if (ret != 0) {
59 delete m_regex; // I don't think I regfree a failed compile?
60 m_regex = 0;
61 }
62}
63#else // notdef USE_REGEXP
64m_str(str) {}
65#endif // USE_REGEXP
66
67RegExp::~RegExp() {
68#ifdef USE_REGEXP
69 if (m_regex != 0) {
70 regfree(m_regex);
71 delete m_regex;
72 }
73#endif // USE_REGEXP
74}
75
76bool RegExp::match(const string &str) const {
77#ifdef USE_REGEXP
78 if (m_regex)
79 return regexec(m_regex, str.c_str(), 0, 0, 0) == 0;
80 else
81 return false;
82#else // notdef USE_REGEXP
83 return (m_str == str);
84#endif // USE_REGEXP
85}
86
87
88bool RegExp::error() const {
89#ifdef USE_REGEXP
90 return m_regex == 0;
91#else
92 return m_str == "";
93#endif // USE_REGEXP
94}
95
96}; // end namespace FbTk
diff --git a/src/FbTk/RegExp.hh b/src/FbTk/RegExp.hh
new file mode 100644
index 0000000..0386670
--- /dev/null
+++ b/src/FbTk/RegExp.hh
@@ -0,0 +1,66 @@
1// RegExp.hh for FbTk
2// Copyright (c) 2002 Xavier Brouckaert
3// Copyright (c) 2003 Henrik Kinnunen (fluxgen at fluxbox dot org)
4// and Simon Bowden (rathnor at users.sourceforge.net)
5//
6// Permission is hereby granted, free of charge, to any person obtaining a
7// copy of this software and associated documentation files (the "Software"),
8// to deal in the Software without restriction, including without limitation
9// the rights to use, copy, modify, merge, publish, distribute, sublicense,
10// and/or sell copies of the Software, and to permit persons to whom the
11// Software is furnished to do so, subject to the following conditions:
12//
13// The above copyright notice and this permission notice shall be included in
14// all copies or substantial portions of the Software.
15//
16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22// DEALINGS IN THE SOFTWARE.
23
24#ifndef FBTK_REGEXP_HH
25#define FBTK_REGEXP_HH
26
27#include "NotCopyable.hh"
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif // HAVE_CONFIG_H
32
33#include <string>
34
35/*
36 * If USE_REGEXP isn't defined, then we match just using simple string equality
37 */
38
39#ifdef USE_REGEXP
40#include <sys/types.h>
41#include <regex.h>
42#endif // USE_REGEXP
43
44namespace FbTk {
45
46class RegExp: private NotCopyable {
47public:
48 RegExp(const std::string &str, bool full_match = true);
49 ~RegExp();
50
51 bool match(const std::string &str) const;
52
53 bool error() const;
54
55private:
56#ifdef USE_REGEXP
57 regex_t* m_regex;
58#else // notdef USE_REGEXP
59 std::string m_str;
60#endif // USE_REGEXP
61
62};
63
64}; // end namespace FbTk
65
66#endif // FBTK_REGEXP_HH