* \param s Pointer to the src string for memcpy.
* \param len len of the string sent in s.
*/
-static inline void memcpy_tolower(uint8_t *d, uint8_t *s, uint16_t len)
+static inline void memcpy_tolower(uint8_t *d, const uint8_t *s, uint16_t len)
{
uint16_t i;
for (i = 0; i < len; i++)
* \retval BmCtx pointer to the newly created Context for the pattern
* \initonly BoyerMoore contexts should be created at init
*/
-BmCtx *BoyerMooreCtxInit(uint8_t *needle, uint16_t needle_len)
+BmCtx *BoyerMooreCtxInit(const uint8_t *needle, uint16_t needle_len)
{
BmCtx *new = SCMalloc(sizeof(BmCtx));
if (unlikely(new == NULL)) {
*
* \retval ptr to start of the match; NULL if no match
*/
-uint8_t *BoyerMoore(uint8_t *x, uint16_t m, uint8_t *y, int32_t n, BmCtx *bm_ctx)
+uint8_t *BoyerMoore(const uint8_t *x, uint16_t m, const uint8_t *y, int32_t n, BmCtx *bm_ctx)
{
uint16_t *bmGs = bm_ctx->bmGs;
uint16_t *bmBc = bm_ctx->bmBc;
for (i = m - 1; i >= 0 && x[i] == y[i + j]; --i);
if (i < 0) {
- return y + j;
+ return (uint8_t *)(y + j);
//j += bmGs[0];
} else {
// printf("%c", y[i+j]);
*
* \retval ptr to start of the match; NULL if no match
*/
-uint8_t *BoyerMooreNocase(uint8_t *x, uint16_t m, uint8_t *y, int32_t n, BmCtx *bm_ctx)
+uint8_t *BoyerMooreNocase(const uint8_t *x, uint16_t m, const uint8_t *y, int32_t n, BmCtx *bm_ctx)
{
uint16_t *bmGs = bm_ctx->bmGs;
uint16_t *bmBc = bm_ctx->bmBc;
for (i = m - 1; i >= 0 && x[i] == u8_tolower(y[i + j]); --i);
if (i < 0) {
- return y + j;
+ return (uint8_t *)(y + j);
} else {
j += (m1=bmGs[i]) > (m2=bmBc[u8_tolower(y[i + j])] - m + 1 + i)?m1:m2;
}
} BmCtx;
/** Prepare and return a Boyer Moore context */
-BmCtx *BoyerMooreCtxInit(uint8_t *needle, uint16_t needle_len);
+BmCtx *BoyerMooreCtxInit(const uint8_t *needle, uint16_t needle_len);
BmCtx *BoyerMooreNocaseCtxInit(uint8_t *needle, uint16_t needle_len);
void BoyerMooreCtxToNocase(BmCtx *, uint8_t *, uint16_t);
-uint8_t *BoyerMoore(uint8_t *x, uint16_t m, uint8_t *y, int32_t n, BmCtx *bm_ctx);
-uint8_t *BoyerMooreNocase(uint8_t *x, uint16_t m, uint8_t *y, int32_t n, BmCtx *bm_ctx);
+uint8_t *BoyerMoore(const uint8_t *x, uint16_t m, const uint8_t *y, int32_t n, BmCtx *bm_ctx);
+uint8_t *BoyerMooreNocase(const uint8_t *x, uint16_t m, const uint8_t *y, int32_t n, BmCtx *bm_ctx);
void BoyerMooreCtxDeInit(BmCtx *);
#endif /* __UTIL_SPM_BM__ */
* \param needle pattern to search for
* \param needlelen length of the pattern
*/
-uint8_t *Bs2bmSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen)
+uint8_t *Bs2bmSearch(const uint8_t *text, uint32_t textlen,
+ const uint8_t *needle, uint16_t needlelen)
{
uint8_t badchars[ALPHABET_SIZE];
Bs2BmBadchars(needle, needlelen, badchars);
* \param needle pattern to search for
* \param needlelen length of the pattern
*/
-uint8_t *Bs2bmNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen)
+uint8_t *Bs2bmNocaseSearch(const uint8_t *text, uint32_t textlen,
+ const uint8_t *needle, uint16_t needlelen)
{
uint8_t badchars[ALPHABET_SIZE];
Bs2BmBadchars(needle, needlelen, badchars);
* \param needle pattern to search for
* \param needlelen length of the pattern
*/
-uint8_t *BoyerMooreSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen)
+uint8_t *BoyerMooreSearch(const uint8_t *text, uint32_t textlen,
+ const uint8_t *needle, uint16_t needlelen)
{
BmCtx *bm_ctx = BoyerMooreCtxInit(needle, needlelen);
* \param needle pattern to search for
* \param needlelen length of the pattern
*/
-uint8_t *BoyerMooreNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen)
+uint8_t *BoyerMooreNocaseSearch(const uint8_t *text, uint32_t textlen,
+ uint8_t *needle, uint16_t needlelen)
{
BmCtx *bm_ctx = BoyerMooreNocaseCtxInit(needle, needlelen);
#include "util-spm-bm.h"
/** Default algorithm to use: Boyer Moore */
-uint8_t *Bs2bmSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen);
-uint8_t *Bs2bmNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen);
-uint8_t *BoyerMooreSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen);
-uint8_t *BoyerMooreNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen);
+uint8_t *Bs2bmSearch(const uint8_t *text, uint32_t textlen, const uint8_t *needle, uint16_t needlelen);
+uint8_t *Bs2bmNocaseSearch(const uint8_t *text, uint32_t textlen, const uint8_t *needle, uint16_t needlelen);
+uint8_t *BoyerMooreSearch(const uint8_t *text, uint32_t textlen, const uint8_t *needle, uint16_t needlelen);
+uint8_t *BoyerMooreNocaseSearch(const uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen);
/* Macros for automatic algorithm selection (use them only when you can't store the context) */
#define SpmSearch(text, textlen, needle, needlelen) ({\