From 65f35b5df50051118765392e11a35094df80190f Mon Sep 17 00:00:00 2001 From: Joonwoo Park Date: Tue, 8 Jul 2008 02:37:54 -0700 Subject: [PATCH] --- yaml --- r: 103327 b: refs/heads/master c: 3b76d08190e6b420ed3f5534aa99ee29d82d731f h: refs/heads/master i: 103325: 7a41d291ac5e1b72cae3c168c7ebc50769ae2f02 103323: bd419358a30a1b46622de1d95d55121081d88bf6 103319: 735b2039886cbd39b52c49e0ab0c10444848ceb1 103311: a797481025f02ceddc311025d1a6a3d20766b2bb 103295: bb342bfe614743e9536251dfd91bea198397066e v: v3 --- [refs] | 2 +- trunk/lib/ts_bm.c | 26 ++++++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/[refs] b/[refs] index fc831a3689fa..3ad4cb5410bb 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: b9c796783151678d08b1ec1ef410685b2515ba51 +refs/heads/master: 3b76d08190e6b420ed3f5534aa99ee29d82d731f diff --git a/trunk/lib/ts_bm.c b/trunk/lib/ts_bm.c index 4a7fce72898e..9e66ee4020e9 100644 --- a/trunk/lib/ts_bm.c +++ b/trunk/lib/ts_bm.c @@ -39,6 +39,7 @@ #include #include #include +#include #include /* Alphabet size, use ASCII */ @@ -64,6 +65,7 @@ static unsigned int bm_find(struct ts_config *conf, struct ts_state *state) unsigned int i, text_len, consumed = state->offset; const u8 *text; int shift = bm->patlen - 1, bs; + const u8 icase = conf->flags & TS_IGNORECASE; for (;;) { text_len = conf->get_next_block(consumed, &text, conf, state); @@ -75,7 +77,9 @@ static unsigned int bm_find(struct ts_config *conf, struct ts_state *state) DEBUGP("Searching in position %d (%c)\n", shift, text[shift]); for (i = 0; i < bm->patlen; i++) - if (text[shift-i] != bm->pattern[bm->patlen-1-i]) + if ((icase ? toupper(text[shift-i]) + : text[shift-i]) + != bm->pattern[bm->patlen-1-i]) goto next; /* London calling... */ @@ -111,14 +115,18 @@ static int subpattern(u8 *pattern, int i, int j, int g) return ret; } -static void compute_prefix_tbl(struct ts_bm *bm) +static void compute_prefix_tbl(struct ts_bm *bm, int flags) { int i, j, g; for (i = 0; i < ASIZE; i++) bm->bad_shift[i] = bm->patlen; - for (i = 0; i < bm->patlen - 1; i++) + for (i = 0; i < bm->patlen - 1; i++) { bm->bad_shift[bm->pattern[i]] = bm->patlen - 1 - i; + if (flags & TS_IGNORECASE) + bm->bad_shift[tolower(bm->pattern[i])] + = bm->patlen - 1 - i; + } /* Compute the good shift array, used to match reocurrences * of a subpattern */ @@ -135,10 +143,11 @@ static void compute_prefix_tbl(struct ts_bm *bm) } static struct ts_config *bm_init(const void *pattern, unsigned int len, - gfp_t gfp_mask) + gfp_t gfp_mask, int flags) { struct ts_config *conf; struct ts_bm *bm; + int i; unsigned int prefix_tbl_len = len * sizeof(unsigned int); size_t priv_size = sizeof(*bm) + len + prefix_tbl_len; @@ -146,11 +155,16 @@ static struct ts_config *bm_init(const void *pattern, unsigned int len, if (IS_ERR(conf)) return conf; + conf->flags = flags; bm = ts_config_priv(conf); bm->patlen = len; bm->pattern = (u8 *) bm->good_shift + prefix_tbl_len; - memcpy(bm->pattern, pattern, len); - compute_prefix_tbl(bm); + if (flags & TS_IGNORECASE) + for (i = 0; i < len; i++) + bm->pattern[i] = toupper(((u8 *)pattern)[i]); + else + memcpy(bm->pattern, pattern, len); + compute_prefix_tbl(bm, flags); return conf; }