apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Pane <bp...@pacbell.net>
Subject new string matching API
Date Wed, 08 May 2002 04:26:06 GMT
I put together an abstract API for string matching, plus a
concrete "subclass" that implements a simplified form of
Boyer-Moore.  (The point of the design is to allow different
search implementations to be plugged in as needed.  We could,
for example, add a BNDM implementation for use in apps where
BNDM is a better choice than Boyer-Moore.)

All the places where I'm thinking of using this code are in
the httpd, but I suspect that it may be useful for other APR-based
projects.

Does anyone have strong opinions for or against adding
this to apr-util?

Thanks,
--Brian

#ifndef APR_STRMATCH_H
#define APR_STRMATCH_H
/**
 * @file apr_strmatch.h
 * @brief APR-UTIL string matching routines
 */
#ifdef __cplusplus
extern "C" {
#endif

/**
 * @defgroup APR_Util_StrMatch String matching routines
 * @ingroup APR_Util
 * @{
 */


#include "apu.h"
#include "apr_pools.h"


typedef struct apr_strmatch_pattern apr_strmatch_pattern;
/**
 * Precompiled search pattern
 */
struct apr_strmatch_pattern {
    const char *(*compare)(const apr_strmatch_pattern *this_pattern,
                            const char *s, apr_size_t slen);
    const char *pattern;
    apr_size_t length;
    void *context;  /* hook for subclasses to add precomputed metadata */
};

#if defined(DOXYGEN)
/**
 * Search for a precompiled pattern within a string
 * @param pattern The pattern
 * @param s The string in which to search for the pattern
 * @param slen The length of s (excluding null terminator)
 * @return A pointer to the first instance of the pattern in s, or
 *         NULL if not found
 */
APU_DECLARE(const char *) apr_strmatch(const apr_strmatch_pattern *pattern,
                                       const char *s; apr_size_t s);
#else
#define apr_strmatch(pattern, s, slen) 
(*((pattern)->compare))((pattern), (s), (slen))
#endif

/**
 * Precompile a pattern for matching using the Boyer-Moore-Horspool 
algorithm
 * @param p The pool from which to allocate the pattern
 * @param s The pattern string
 * @param case_sensitive Whether the matching should be case-sensitive
 * @return a pointer to the compiled pattern, or NULL if compilation fails
 */
APU_DECLARE(const apr_strmatch_pattern *)
         apr_strmatch_precompile(apr_pool_t *p, const char *s,
                                 int case_sensitive);

/** @} */
#ifdef __cplusplus
}
#endif

#endif    /* !APR_STRMATCH_H */



Mime
View raw message