15namespace alib {
namespace strings {
namespace util {
18template<
typename TChar, lang::Case TSensitivity>
25template<
typename TChar, lang::Case TSensitivity>
33 needle.Reset( pNeedle );
34 if( needle.Length() == 0 )
37 if( kmpTableLength < needle.Length() )
42 kmpTable=
new integer[size_t( needle.Length() + 1 )];
43 kmpTableLength= needle.Length();
46 integer pfxLen= kmpTable[0]= -1;
51 pfxLen= kmpTable[pfxLen];
53 if (needleIdx == needle.Length())
59 kmpTable[needleIdx]= pfxLen;
63template<
typename TChar, lang::Case TSensitivity>
66 if ( needle.IsNull() )
68 if ( haystackIdx < 0 ) haystackIdx= 0;
69 if ( haystackIdx + needle.Length() > haystack.
Length() )
return -1;
71 if( needle.Length() == 0 )
75 while (haystackIdx != haystack.
Length())
79 needle .Buffer()[needleIdx] ) )
80 needleIdx= kmpTable[needleIdx];
84 if ( needleIdx >= needle.Length() )
85 return (haystackIdx - needleIdx);
constexpr bool IsNull() const
constexpr integer Length() const
constexpr const TChar * Buffer() const
ALIB_API ~TSubstringSearch()
Destructor.
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
bool Equal(TChar lhs, TRhs rhs)
lang::integer integer
Type alias in namespace alib.