diff options
author | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-06-24 09:20:43 +0000 |
---|---|---|
committer | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-06-24 09:20:43 +0000 |
commit | c1d6a946fbdb5eff8571675cece333e87a9b9d07 (patch) | |
tree | af2e8a0a84bea0afb8c8c24ace6764091e9aa7f0 /crawl-ref/source/libutil.cc | |
parent | bc8d3fba7bf6518a07bcb2e5b1843bedd41ccf41 (diff) | |
download | crawl-ref-c1d6a946fbdb5eff8571675cece333e87a9b9d07.tar.gz crawl-ref-c1d6a946fbdb5eff8571675cece333e87a9b9d07.zip |
Allow glob patterns in KFEAT lines. For instance:
KFEAT: A = gate * Abyss
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1633 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/libutil.cc')
-rw-r--r-- | crawl-ref/source/libutil.cc | 62 |
1 files changed, 39 insertions, 23 deletions
diff --git a/crawl-ref/source/libutil.cc b/crawl-ref/source/libutil.cc index 98dd7f598f..042615ee64 100644 --- a/crawl-ref/source/libutil.cc +++ b/crawl-ref/source/libutil.cc @@ -381,6 +381,40 @@ static bool glob_match( const char *pattern, const char *text, bool icase ) } } +//////////////////////////////////////////////////////////////////// +// Basic glob (always available) + +struct glob_info +{ + std::string s; + bool ignore_case; +}; + +void *compile_glob_pattern(const char *pattern, bool icase) +{ + // If we're using simple globs, we need to box the pattern with '*' + std::string s = std::string("*") + pattern + "*"; + glob_info *gi = new glob_info; + if (gi) + { + gi->s = s; + gi->ignore_case = icase; + } + return gi; +} + +void free_compiled_glob_pattern(void *compiled_pattern) +{ + delete static_cast<glob_info *>( compiled_pattern ); +} + +bool glob_pattern_match(void *compiled_pattern, const char *text, int length) +{ + glob_info *gi = static_cast<glob_info *>( compiled_pattern ); + return glob_match(gi->s.c_str(), text, gi->ignore_case); +} +//////////////////////////////////////////////////////////////////// + #if defined(REGEX_PCRE) //////////////////////////////////////////////////////////////////// // Perl Compatible Regular Expressions @@ -459,38 +493,20 @@ bool pattern_match(void *compiled_pattern, const char *text, int length) //////////////////////////////////////////////////////////////////// #else -//////////////////////////////////////////////////////////////////// -// Basic glob -struct glob_info -{ - std::string s; - bool ignore_case; -}; - -void *compile_pattern(const char *pattern, bool icase) +void *compile_pattern(const char *pattern, bool icase) { - // If we're using simple globs, we need to box the pattern with '*' - std::string s = std::string("*") + pattern + "*"; - glob_info *gi = new glob_info; - if (gi) - { - gi->s = s; - gi->ignore_case = icase; - } - return gi; + return compile_glob_pattern(pattern, icase); } -void free_compiled_pattern(void *compiled_pattern) +void free_compiled_pattern(void *cp) { - delete static_cast<glob_info *>( compiled_pattern ); + free_compiled_glob_pattern(cp); } bool pattern_match(void *compiled_pattern, const char *text, int length) { - glob_info *gi = static_cast<glob_info *>( compiled_pattern ); - return glob_match(gi->s.c_str(), text, gi->ignore_case); + return glob_pattern_match(compiled_pattern, text, length); } -//////////////////////////////////////////////////////////////////// #endif |