3 * Copyright (c) 1998-2000
6 * Permission to use, copy, modify, distribute and sell this software
7 * and its documentation for any purpose is hereby granted without fee,
8 * provided that the above copyright notice appear in all copies and
9 * that both that copyright notice and this permission notice appear
10 * in supporting documentation. Dr John Maddock makes no representations
11 * about the suitability of this software for any purpose.
12 * It is provided "as is" without express or implied warranty.
17 * LOCATION: see http://www.boost.org for most recent version.
20 * DESCRIPTION: Provides Knuth Morris Pratt search operations.
21 * Note this is an internal header file included
22 * by regex.hpp, do not include on its own.
25 #ifndef BOOST_REGEX_KMP_HPP
26 #define BOOST_REGEX_KMP_HPP
28 #ifdef BOOST_REGEX_CONFIG_HPP
29 #include <boost/re_detail/regex_config.hpp>
37 #if __BORLANDC__ == 0x530
38 #pragma option push -a4 -b -Ve
39 #elif __BORLANDC__ > 0x530
40 #pragma option push -a8 -b -Ve
44 template <class charT>
53 template <class charT, class Allocator>
54 void kmp_free(kmp_info<charT>* pinfo, Allocator a)
56 typedef BOOST_RE_MAYBE_TYPENAME REBIND_TYPE(char, Allocator) atype;
57 atype(a).deallocate((char*)pinfo, pinfo->size);
60 template <class iterator, class charT, class Trans, class Allocator>
61 kmp_info<charT>* kmp_compile(iterator first, iterator last, charT, Trans translate, Allocator a)
63 typedef BOOST_RE_MAYBE_TYPENAME REBIND_TYPE(char, Allocator) atype;
66 BOOST_RE_DISTANCE(first, last, m);
68 unsigned int size = sizeof(kmp_info<charT>) + sizeof(int)*m + sizeof(charT)*m;
71 // allocate struct and fill it in:
73 kmp_info<charT>* pinfo = (kmp_info<charT>*)atype(a).allocate(size);
76 charT* p = (charT*)((char*)pinfo + sizeof(kmp_info<charT>) + sizeof(int)*(m+1));
80 *p = translate(*first);
86 // finally do regular kmp compile:
88 j = pinfo->kmp_next[0] = -1;
91 while ((j > -1) && (pinfo->pstr[i] != pinfo->pstr[j]))
92 j = pinfo->kmp_next[j];
95 if (pinfo->pstr[i] == pinfo->pstr[j])
96 pinfo->kmp_next[i] = pinfo->kmp_next[j];
98 pinfo->kmp_next[i] = j;
105 #if __BORLANDC__ > 0x520
110 } // namepsace re_detail
113 #endif // BOOST_REGEX_KMP_HPP