summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/pattern.h
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2012-10-29 05:57:36 +0100
committerAdam Borowski <kilobyte@angband.pl>2012-10-31 22:59:39 +0100
commit6bd4f176038ec9b3704ffe4b1522eff582a0b144 (patch)
tree061d8363896691282274e0be8e3152ce287790ac /crawl-ref/source/pattern.h
parentf73d0cfe86df169f25b19233024fa3e1acced18a (diff)
downloadcrawl-ref-6bd4f176038ec9b3704ffe4b1522eff582a0b144.tar.gz
crawl-ref-6bd4f176038ec9b3704ffe4b1522eff582a0b144.zip
Detemplatize text_pattern.
It is included everywhere, complex templates drag down compilation. And what's the point of a template that's instantiated exactly once?
Diffstat (limited to 'crawl-ref/source/pattern.h')
-rw-r--r--crawl-ref/source/pattern.h102
1 files changed, 12 insertions, 90 deletions
diff --git a/crawl-ref/source/pattern.h b/crawl-ref/source/pattern.h
index 00a4d75d3c..204d58914b 100644
--- a/crawl-ref/source/pattern.h
+++ b/crawl-ref/source/pattern.h
@@ -1,30 +1,6 @@
#ifndef PATTERN_H
#define PATTERN_H
-#ifdef REGEX_PCRE
- // Statically link pcre on Windows
- #if defined(TARGET_OS_WINDOWS)
- #define PCRE_STATIC
- #endif
-
- #include <pcre.h>
-#endif
-
-#ifdef REGEX_POSIX
- // Do we still need to include sys/types.h?
- #include <sys/types.h>
- #include <regex.h>
-#endif
-
-// Pattern matching
-void *compile_pattern(const char *pattern, bool ignore_case = false);
-void free_compiled_pattern(void *cp);
-bool pattern_match(void *compiled_pattern, const char *text, int length);
-
-typedef void *(*p_compile)(const char *pattern, bool ignore_case);
-typedef void (*p_free)(void *cp);
-typedef bool (*p_match)(void *compiled_pattern, const char *text, int length);
-
class base_pattern
{
public:
@@ -35,23 +11,22 @@ public:
virtual const string &tostring() const = 0;
};
-template <p_compile pcomp, p_free pfree, p_match pmatch>
-class basic_text_pattern : public base_pattern
+class text_pattern : public base_pattern
{
public:
- basic_text_pattern(const string &s, bool icase = false)
+ text_pattern(const string &s, bool icase = false)
: pattern(s), compiled_pattern(NULL),
isvalid(true), ignore_case(icase)
{
}
- basic_text_pattern()
+ text_pattern()
: pattern(), compiled_pattern(NULL),
isvalid(false), ignore_case(false)
{
}
- basic_text_pattern(const basic_text_pattern &tp)
+ text_pattern(const text_pattern &tp)
: base_pattern(tp),
pattern(tp.pattern),
compiled_pattern(NULL),
@@ -60,59 +35,13 @@ public:
{
}
- ~basic_text_pattern()
- {
- if (compiled_pattern)
- pfree(compiled_pattern);
- }
-
- const basic_text_pattern &operator= (const basic_text_pattern &tp)
- {
- if (this == &tp)
- return tp;
+ ~text_pattern();
+ const text_pattern &operator= (const text_pattern &tp);
+ const text_pattern &operator= (const string &spattern);
+ bool operator== (const text_pattern &tp) const;
+ bool compile() const;
- if (compiled_pattern)
- pfree(compiled_pattern);
- pattern = tp.pattern;
- compiled_pattern = NULL;
- isvalid = tp.isvalid;
- ignore_case = tp.ignore_case;
- return *this;
- }
-
- const basic_text_pattern &operator= (const string &spattern)
- {
- if (pattern == spattern)
- return *this;
-
- if (compiled_pattern)
- pfree(compiled_pattern);
- pattern = spattern;
- compiled_pattern = NULL;
- isvalid = true;
- // We don't change ignore_case
- return *this;
- }
-
- bool operator== (const basic_text_pattern &tp) const
- {
- if (this == &tp)
- return true;
-
- return (pattern == tp.pattern && ignore_case == tp.ignore_case);
- }
-
- bool compile() const
- {
- return !empty()?
- !!(compiled_pattern = pcomp(pattern.c_str(), ignore_case))
- : false;
- }
-
- bool empty() const
- {
- return !pattern.length();
- }
+ bool empty() const { return !pattern.length(); }
bool valid() const
{
@@ -120,14 +49,11 @@ public:
&& (compiled_pattern || (isvalid = compile()));
}
- bool matches(const char *s, int length) const
- {
- return valid() && pmatch(compiled_pattern, s, length);
- }
+ bool matches(const char *s, int length) const;
bool matches(const char *s) const
{
- return matches(string(s));
+ return matches(s, strlen(s));
}
bool matches(const string &s) const
@@ -146,8 +72,4 @@ private:
mutable bool isvalid;
bool ignore_case;
};
-
-typedef
-basic_text_pattern<compile_pattern,
- free_compiled_pattern, pattern_match> text_pattern;
#endif