From c1d6a946fbdb5eff8571675cece333e87a9b9d07 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Sun, 24 Jun 2007 09:20:43 +0000 Subject: 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 --- crawl-ref/source/libutil.cc | 62 ++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 23 deletions(-) (limited to 'crawl-ref/source/libutil.cc') 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( compiled_pattern ); +} + +bool glob_pattern_match(void *compiled_pattern, const char *text, int length) +{ + glob_info *gi = static_cast( 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( compiled_pattern ); + free_compiled_glob_pattern(cp); } bool pattern_match(void *compiled_pattern, const char *text, int length) { - glob_info *gi = static_cast( compiled_pattern ); - return glob_match(gi->s.c_str(), text, gi->ignore_case); + return glob_pattern_match(compiled_pattern, text, length); } -//////////////////////////////////////////////////////////////////// #endif -- cgit v1.2.3-54-g00ecf