3 * Copyright (c) 1998-2002
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.
19 * VERSION see <boost/version.hpp>
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/regex/config.hpp>
37 #pragma option push -a8 -b -Vx -Ve -pc
40 template <class charT>
49 template <class charT, class Allocator>
50 void kmp_free(kmp_info<charT>* pinfo, const Allocator& a)
52 typedef typename boost::detail::rebind_allocator<char, Allocator>::type atype;
53 atype(a).deallocate(reinterpret_cast<char*>(pinfo), pinfo->size);
56 template <class iterator, class charT, class Trans, class Allocator>
57 kmp_info<charT>* kmp_compile(iterator first, iterator last, charT, Trans translate, const Allocator& a)
59 typedef typename boost::detail::rebind_allocator<char, Allocator>::type atype;
62 m = static_cast<int>(boost::re_detail::distance(first, last));
64 unsigned int size = sizeof(kmp_info<charT>) + sizeof(int)*m + sizeof(charT)*m;
67 // allocate struct and fill it in:
69 kmp_info<charT>* pinfo = reinterpret_cast<kmp_info<charT>*>(atype(a).allocate(size));
70 BOOST_REGEX_NOEH_ASSERT(pinfo)
73 charT* p = reinterpret_cast<charT*>(reinterpret_cast<char*>(pinfo) + sizeof(kmp_info<charT>) + sizeof(int)*(m+1));
77 *p = translate(*first);
83 // finally do regular kmp compile:
85 j = pinfo->kmp_next[0] = -1;
88 while ((j > -1) && (pinfo->pstr[i] != pinfo->pstr[j]))
89 j = pinfo->kmp_next[j];
92 if (pinfo->pstr[i] == pinfo->pstr[j])
93 pinfo->kmp_next[i] = pinfo->kmp_next[j];
95 pinfo->kmp_next[i] = j;
105 } // namepsace re_detail
108 #endif // BOOST_REGEX_KMP_HPP