apr_strmatch.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef APR_STRMATCH_H
  17. #define APR_STRMATCH_H
  18. /**
  19. * @file apr_strmatch.h
  20. * @brief APR-UTIL string matching routines
  21. */
  22. #include "apu.h"
  23. #include "apr_pools.h"
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. /**
  28. * @defgroup APR_Util_StrMatch String matching routines
  29. * @ingroup APR_Util
  30. * @{
  31. */
  32. /** @see apr_strmatch_pattern */
  33. typedef struct apr_strmatch_pattern apr_strmatch_pattern;
  34. /**
  35. * Precompiled search pattern
  36. */
  37. struct apr_strmatch_pattern {
  38. /** Function called to compare */
  39. const char *(*compare)(const apr_strmatch_pattern *this_pattern,
  40. const char *s, apr_size_t slen);
  41. const char *pattern; /**< Current pattern */
  42. apr_size_t length; /**< Current length */
  43. void *context; /**< hook to add precomputed metadata */
  44. };
  45. #if defined(DOXYGEN)
  46. /**
  47. * Search for a precompiled pattern within a string
  48. * @param pattern The pattern
  49. * @param s The string in which to search for the pattern
  50. * @param slen The length of s (excluding null terminator)
  51. * @return A pointer to the first instance of the pattern in s, or
  52. * NULL if not found
  53. */
  54. APU_DECLARE(const char *) apr_strmatch(const apr_strmatch_pattern *pattern,
  55. const char *s, apr_size_t slen);
  56. #else
  57. #define apr_strmatch(pattern, s, slen) (*((pattern)->compare))((pattern), (s), (slen))
  58. #endif
  59. /**
  60. * Precompile a pattern for matching using the Boyer-Moore-Horspool algorithm
  61. * @param p The pool from which to allocate the pattern
  62. * @param s The pattern string
  63. * @param case_sensitive Whether the matching should be case-sensitive
  64. * @return a pointer to the compiled pattern, or NULL if compilation fails
  65. */
  66. APU_DECLARE(const apr_strmatch_pattern *) apr_strmatch_precompile(apr_pool_t *p, const char *s, int case_sensitive);
  67. /** @} */
  68. #ifdef __cplusplus
  69. }
  70. #endif
  71. #endif /* !APR_STRMATCH_H */