1251876Speter/* Licensed to the Apache Software Foundation (ASF) under one or more
2251876Speter * contributor license agreements.  See the NOTICE file distributed with
3251876Speter * this work for additional information regarding copyright ownership.
4251876Speter * The ASF licenses this file to You under the Apache License, Version 2.0
5251876Speter * (the "License"); you may not use this file except in compliance with
6251876Speter * the License.  You may obtain a copy of the License at
7251876Speter *
8251876Speter *     http://www.apache.org/licenses/LICENSE-2.0
9251876Speter *
10251876Speter * Unless required by applicable law or agreed to in writing, software
11251876Speter * distributed under the License is distributed on an "AS IS" BASIS,
12251876Speter * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13251876Speter * See the License for the specific language governing permissions and
14251876Speter * limitations under the License.
15251876Speter */
16251876Speter
17251876Speter#ifndef APR_STRMATCH_H
18251876Speter#define APR_STRMATCH_H
19251876Speter/**
20251876Speter * @file apr_strmatch.h
21251876Speter * @brief APR-UTIL string matching routines
22251876Speter */
23251876Speter
24251876Speter#include "apu.h"
25251876Speter#include "apr_pools.h"
26251876Speter
27251876Speter#ifdef __cplusplus
28251876Speterextern "C" {
29251876Speter#endif
30251876Speter
31251876Speter/**
32251876Speter * @defgroup APR_Util_StrMatch String matching routines
33251876Speter * @ingroup APR_Util
34251876Speter * @{
35251876Speter */
36251876Speter
37251876Speter/** @see apr_strmatch_pattern */
38251876Spetertypedef struct apr_strmatch_pattern apr_strmatch_pattern;
39251876Speter
40251876Speter/**
41251876Speter * Precompiled search pattern
42251876Speter */
43251876Speterstruct apr_strmatch_pattern {
44251876Speter    /** Function called to compare */
45251876Speter    const char *(*compare)(const apr_strmatch_pattern *this_pattern,
46251876Speter                           const char *s, apr_size_t slen);
47251876Speter    const char *pattern;    /**< Current pattern */
48251876Speter    apr_size_t length;      /**< Current length */
49251876Speter    void *context;          /**< hook to add precomputed metadata */
50251876Speter};
51251876Speter
52251876Speter#if defined(DOXYGEN)
53251876Speter/**
54251876Speter * Search for a precompiled pattern within a string
55251876Speter * @param pattern The pattern
56251876Speter * @param s The string in which to search for the pattern
57251876Speter * @param slen The length of s (excluding null terminator)
58251876Speter * @return A pointer to the first instance of the pattern in s, or
59251876Speter *         NULL if not found
60251876Speter */
61251876SpeterAPU_DECLARE(const char *) apr_strmatch(const apr_strmatch_pattern *pattern,
62251876Speter                                       const char *s, apr_size_t slen);
63251876Speter#else
64251876Speter#define apr_strmatch(pattern, s, slen) (*((pattern)->compare))((pattern), (s), (slen))
65251876Speter#endif
66251876Speter
67251876Speter/**
68251876Speter * Precompile a pattern for matching using the Boyer-Moore-Horspool algorithm
69251876Speter * @param p The pool from which to allocate the pattern
70251876Speter * @param s The pattern string
71251876Speter * @param case_sensitive Whether the matching should be case-sensitive
72251876Speter * @return a pointer to the compiled pattern, or NULL if compilation fails
73251876Speter */
74251876SpeterAPU_DECLARE(const apr_strmatch_pattern *) apr_strmatch_precompile(apr_pool_t *p, const char *s, int case_sensitive);
75251876Speter
76251876Speter/** @} */
77251876Speter#ifdef __cplusplus
78251876Speter}
79251876Speter#endif
80251876Speter
81251876Speter#endif	/* !APR_STRMATCH_H */
82