1
/* This file is part of Strigi Desktop Search
3
* Copyright (C) 2006 Jos van den Oever <jos@vandenoever.info>
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Library General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Library General Public License for more details.
15
* You should have received a copy of the GNU Library General Public License
16
* along with this library; see the file COPYING.LIB. If not, write to
17
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
* Boston, MA 02110-1301, USA.
20
#ifndef STRIGI_KMPSEARCHER_H
21
#define STRIGI_KMPSEARCHER_H
26
#include <strigi/strigiconfig.h>
30
* Class for string search that uses the Knuth-Morris-Pratt algorithm.
31
* Code based on the example on
32
* http://en.wikipedia.org/wiki/Knuth-Morris-Pratt_algorithm
34
class STREAMS_EXPORT KmpSearcher {
41
KmpSearcher() :table(0) { }
42
KmpSearcher(const std::string& query);
48
void setQuery(const std::string& query);
49
int32_t queryLength() const { return len; }
50
std::string query() const { return m_query; }
52
* @brief Find the needle in @p haystack.
53
* @param haystack the text to search in.
54
* @param haylen the length of the text to search in.
55
* @return a pointer to the start of the match if a match is found
58
const char* search(const char* haystack, int32_t haylen) const;
61
} // end namespace Strigi