ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::strings::util::TStringSearch< TChar, TSensitivity > Class Template Reference

Description:

template<typename TChar, lang::Case TSensitivity = lang::Case::Sensitive>
class alib::strings::util::TStringSearch< TChar, TSensitivity >

Implements "Knuth-Morris-Pratt" algorithm for searching a substring within a string.

While the well known "Boyer-Moore-Algorithm" is even faster in the average case, for uni-code characters its implementation would be efficient only with very long haystack strings.

For convenience, the following alias type names are available:

Template Parameters
TCharThe character type of the haystack and needle strings.
TSensitivityThe letter case sensitivity of the search..

Definition at line 25 of file search.inl.

Collaboration diagram for alib::strings::util::TStringSearch< TChar, TSensitivity >:
[legend]

Public Method Index:

 TStringSearch (const TString< TChar > &pNeedle=nullptr)
 
ALIB_DLL ~TStringSearch ()
 Destructor.
 
ALIB_DLL void Compile (const TString< TChar > &needle)
 
ALIB_DLL integer Search (const TString< TChar > &haystack, integer startIdx=0)
 

Protected Field Index:

integerkmpTable = nullptr
 The Knuth-Morris-Pratt prefix length table.
 
integer kmpTableLength = 0
 Length of kmpTable.
 
TAString< TChar, lang::HeapAllocatorneedle
 The needle set Knuth-Morris-Pratt prefix length table.
 

Field Details:

◆ kmpTable

template<typename TChar, lang::Case TSensitivity = lang::Case::Sensitive>
integer* alib::strings::util::TStringSearch< TChar, TSensitivity >::kmpTable = nullptr
protected

The Knuth-Morris-Pratt prefix length table.

Definition at line 32 of file search.inl.

◆ kmpTableLength

template<typename TChar, lang::Case TSensitivity = lang::Case::Sensitive>
integer alib::strings::util::TStringSearch< TChar, TSensitivity >::kmpTableLength = 0
protected

Length of kmpTable.

Definition at line 35 of file search.inl.

◆ needle

template<typename TChar, lang::Case TSensitivity = lang::Case::Sensitive>
TAString<TChar, lang::HeapAllocator> alib::strings::util::TStringSearch< TChar, TSensitivity >::needle
protected

The needle set Knuth-Morris-Pratt prefix length table.

Definition at line 29 of file search.inl.

Constructor(s) / Destructor Details:

◆ TStringSearch()

template<typename TChar, lang::Case TSensitivity = lang::Case::Sensitive>
template ALIB_DLL alib::strings::util::TStringSearch< TChar, TSensitivity >::TStringSearch ( const TString< TChar > & pNeedle = nullptr)
inline

Constructor. Passes the optional parameters to method Compile.

Parameters
pNeedleThe string to search. Defaults to NULL_STRING to allow parameterless construction with later invocation of Compile.

Definition at line 45 of file search.inl.

◆ ~TStringSearch()

template<typename TChar, lang::Case TSensitivity>
template ALIB_DLL alib::strings::util::TStringSearch< TChar, TSensitivity >::~TStringSearch ( )

Destructor.

Definition at line 28 of file search.cpp.

Method Details:

◆ Compile()

template<typename TChar, lang::Case TSensitivity>
template ALIB_DLL void alib::strings::util::TStringSearch< TChar, TSensitivity >::Compile ( const TString< TChar > & needle)

Resets this object to use the given string as the needle to search.

Parameters
needleThe needle to search.

Definition at line 31 of file search.cpp.

Here is the call graph for this function:

◆ Search()

template<typename TChar, lang::Case TSensitivity>
template ALIB_DLL integer alib::strings::util::TStringSearch< TChar, TSensitivity >::Search ( const TString< TChar > & haystack,
integer startIdx = 0 )

Searches for the needle in haystack starting at startIdx.

Parameters
haystackThe string to search in.
startIdxThe start of the search. Defaults to 0.
Returns
The index of the next occurrence of the needle in given haystack. -1 if not found.

Definition at line 67 of file search.cpp.

Here is the call graph for this function:

The documentation for this class was generated from the following files: