45 lines
1.9 KiB
C
45 lines
1.9 KiB
C
#ifndef INCLUDED_C_STRINDEXKMP_H
|
|
#define INCLUDED_C_STRINDEXKMP_H
|
|
|
|
#ifndef INCLUDED_C_TYPES_H
|
|
#include <c_Types.h>
|
|
#endif /*INCLUDED_C_TYPES_H*/
|
|
|
|
#ifndef INCLUDED_C_ALLOCATOR_H
|
|
#include <c_Allocator.h>
|
|
#endif /*INCLUDED_C_ALLOCATOR_H*/
|
|
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
|
/* */
|
|
|
|
#define C_KMP_NOT_FOUND ((c_size_t)-1)
|
|
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
|
/* */
|
|
|
|
/**
|
|
* @brief 工业级 KMP 泛型字节/文本匹配检索器 (Knuth-Morris-Pratt Pattern Matcher)
|
|
* @param text 源文本大连续缓冲区指针
|
|
* @param text_len 源文本缓冲区的实际物理字节长(传入 0 则内部自动按 strlen 计算)
|
|
* @param pattern 待查找的目标特征模式串指针
|
|
* @param pattern_len 模式串的实际物理字节长(传入 0 则内部自动按 strlen 计算)
|
|
* @param start_offset 允许指定的接力检索起始虚拟偏移位置(0 代表从头开始检索)
|
|
* @param allocator 自定义多态分配器引用,若传入 NULL 则无缝降级为全局默认 c_DefaultAllocator
|
|
* @return c_size_t 匹配成功的首个相对物理偏移量,若检索失败则严格返回 C_KMP_NOT_FOUND
|
|
*/
|
|
c_size_t c_StrIndexKmpEx(const void* text, c_size_t text_len,
|
|
const void* pattern, c_size_t pattern_len,
|
|
c_size_t start_offset, c_Allocator_t* allocator);
|
|
|
|
|
|
|
|
// 你给出的原厂极简标准库兼容版桥接接口 (支持直接对齐普通裸 C 字符串字符串)
|
|
C_STATIC_FORCE_INLINE
|
|
c_size_t c_StrIndexKmp(const char* text, const char* pattern) {
|
|
if (!text || !pattern) return C_KMP_NOT_FOUND;
|
|
// 自动桥接至全装全配置的多态安全内核中,降级为默认分配器
|
|
return c_StrIndexKmpEx(text, 0, pattern, 0, 0, NULL);
|
|
}
|
|
|
|
#endif /*INCLUDED_C_STRINDEXKMP_H*/
|