spm: constify search args

pull/1886/merge
Victor Julien 10 years ago
parent 914f7fa733
commit 6e3514a444

@ -35,7 +35,7 @@
* \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++)

@ -73,7 +73,7 @@ void BoyerMooreCtxToNocase(BmCtx *bm_ctx, uint8_t *needle, uint16_t needle_len)
* \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)) {
@ -302,7 +302,7 @@ static void PreBmGsNocase(const uint8_t *x, uint16_t m, uint16_t *bmGs)
*
* \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;
@ -324,7 +324,7 @@ uint8_t *BoyerMoore(uint8_t *x, uint16_t m, uint8_t *y, int32_t n, BmCtx *bm_ctx
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]);
@ -351,7 +351,7 @@ uint8_t *BoyerMoore(uint8_t *x, uint16_t m, uint8_t *y, int32_t n, BmCtx *bm_ctx
*
* \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;
@ -372,7 +372,7 @@ uint8_t *BoyerMooreNocase(uint8_t *x, uint16_t m, uint8_t *y, int32_t n, BmCtx *
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;
}

@ -37,12 +37,12 @@ typedef struct BmCtx_ {
} 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__ */

@ -68,7 +68,8 @@
* \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);
@ -84,7 +85,8 @@ uint8_t *Bs2bmSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t
* \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);
@ -101,7 +103,8 @@ uint8_t *Bs2bmNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uin
* \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);
@ -120,7 +123,8 @@ uint8_t *BoyerMooreSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint
* \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);

@ -29,10 +29,10 @@
#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) ({\

Loading…
Cancel
Save