ALib C++ Library
Library Version: 2312 R0
Documentation generated by doxygen
Public Methods | Protected Fields | List of all members
TSubstringSearch< TChar, TSensitivity > Class Template Reference

#include <subsearch.hpp>

Class Description

template<typename TChar, Case TSensitivity = Case::Sensitive>
class aworx::lib::strings::util::TSubstringSearch< TChar, TSensitivity >


Implements "Knuth-Morris-Pratt" algorithm for searching a sub-string 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 33 of file subsearch.hpp.

Public Methods

 TSubstringSearch (const TString< TChar > &pNeedle=nullptr)
 
ALIB_API ~TSubstringSearch ()
 
ALIB_API void Compile (const TString< TChar > &needle)
 
ALIB_API integer Search (const TString< TChar > &haystack, integer startIdx=0)
 

Protected Fields

integerkmpTable = nullptr
 
integer kmpTableLength = 0
 
TAString< TChar > needle
 

Constructor & Destructor Documentation

◆ TSubstringSearch()

template ALIB_API TSubstringSearch ( const TString< TChar > &  pNeedle = nullptr)
inline

Constructor. Passes the optional parameters to method Compile.

Parameters
pNeedleThe string to search. Defaults to NullString() to allow parameterless construction with later invocation of Compile.

Definition at line 53 of file subsearch.hpp.

Here is the call graph for this function:

◆ ~TSubstringSearch()

template ALIB_API ~TSubstringSearch ( )

Destructor.

Definition at line 20 of file subsearch.cpp.

Member Function Documentation

◆ Compile()

template ALIB_API void 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 27 of file subsearch.cpp.

Here is the call graph for this function:

◆ Search()

template ALIB_API integer 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 61 of file subsearch.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ kmpTable

integer* kmpTable = nullptr
protected

The Knuth-Morris-Pratt prefix length table.

Definition at line 40 of file subsearch.hpp.

◆ kmpTableLength

integer kmpTableLength = 0
protected

Length of kmpTable.

Definition at line 43 of file subsearch.hpp.

◆ needle

TAString<TChar> needle
protected

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

Definition at line 37 of file subsearch.hpp.


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