10#if !defined (HPP_ALIB_STRINGS_UTIL_SUBSEARCH)
16namespace alib {
namespace strings {
namespace util {
19template<
typename TChar, lang::Case TSensitivity>
26template<
typename TChar, lang::Case TSensitivity>
34 needle.Reset( pNeedle );
35 if( needle.Length() == 0 )
38 if( kmpTableLength < needle.Length() )
43 kmpTable=
new integer[
static_cast<size_t>( needle.Length() + 1 )];
44 kmpTableLength= needle.Length();
47 integer pfxLen= kmpTable[0]= -1;
48 while (needleIdx != needle.Length())
52 pfxLen= kmpTable[pfxLen];
60template<
typename TChar, lang::Case TSensitivity>
63 if ( needle.IsNull() )
65 if ( haystackIdx < 0 ) haystackIdx= 0;
66 if ( haystackIdx + needle.Length() > haystack.
Length() )
return -1;
68 if( needle.Length() == 0 )
72 while (haystackIdx != haystack.
Length())
76 needle .Buffer()[needleIdx] ) )
77 needleIdx= kmpTable[needleIdx];
81 if ( needleIdx >= needle.Length() )
82 return (haystackIdx - needleIdx);
constexpr bool IsNull() const
constexpr integer Length() const
constexpr const TChar * Buffer() const
ALIB_API ~TSubstringSearch()
TSubstringSearch(const TString< TChar > &pNeedle=nullptr)
ALIB_API integer Search(const TString< TChar > &haystack, integer startIdx=0)
ALIB_API void Compile(const TString< TChar > &needle)
#define ALIB_WARNINGS_RESTORE
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
lang::integer integer
Type alias in namespace alib.