Commit b9c796783151678d08b1ec1ef410685b2515ba51
Committed by
David S. Miller
1 parent
58de7862e6
Exists in
master
and in
20 other branches
textsearch: support for case insensitive searching
The function textsearch_prepare has a new flag to support case insensitive searching. Signed-off-by: Joonwoo Park <joonwpark81@gmail.com> Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 2 changed files with 13 additions and 11 deletions Side-by-side Diff
include/linux/textsearch.h
... | ... | @@ -10,10 +10,8 @@ |
10 | 10 | |
11 | 11 | struct ts_config; |
12 | 12 | |
13 | -/** | |
14 | - * TS_AUTOLOAD - Automatically load textsearch modules when needed | |
15 | - */ | |
16 | -#define TS_AUTOLOAD 1 | |
13 | +#define TS_AUTOLOAD 1 /* Automatically load textsearch modules when needed */ | |
14 | +#define TS_IGNORECASE 2 /* Searches string case insensitively */ | |
17 | 15 | |
18 | 16 | /** |
19 | 17 | * struct ts_state - search state |
... | ... | @@ -39,7 +37,7 @@ |
39 | 37 | struct ts_ops |
40 | 38 | { |
41 | 39 | const char *name; |
42 | - struct ts_config * (*init)(const void *, unsigned int, gfp_t); | |
40 | + struct ts_config * (*init)(const void *, unsigned int, gfp_t, int); | |
43 | 41 | unsigned int (*find)(struct ts_config *, |
44 | 42 | struct ts_state *); |
45 | 43 | void (*destroy)(struct ts_config *); |
46 | 44 | |
... | ... | @@ -52,12 +50,14 @@ |
52 | 50 | /** |
53 | 51 | * struct ts_config - search configuration |
54 | 52 | * @ops: operations of chosen algorithm |
53 | + * @flags: flags | |
55 | 54 | * @get_next_block: callback to fetch the next block to search in |
56 | 55 | * @finish: callback to finalize a search |
57 | 56 | */ |
58 | 57 | struct ts_config |
59 | 58 | { |
60 | 59 | struct ts_ops *ops; |
60 | + int flags; | |
61 | 61 | |
62 | 62 | /** |
63 | 63 | * get_next_block - fetch next block of data |
lib/textsearch.c
... | ... | @@ -54,10 +54,13 @@ |
54 | 54 | * USAGE |
55 | 55 | * |
56 | 56 | * Before a search can be performed, a configuration must be created |
57 | - * by calling textsearch_prepare() specyfing the searching algorithm and | |
58 | - * the pattern to look for. The returned configuration may then be used | |
59 | - * for an arbitary amount of times and even in parallel as long as a | |
60 | - * separate struct ts_state variable is provided to every instance. | |
57 | + * by calling textsearch_prepare() specifying the searching algorithm, | |
58 | + * the pattern to look for and flags. As a flag, you can set TS_IGNORECASE | |
59 | + * to perform case insensitive matching. But it might slow down | |
60 | + * performance of algorithm, so you should use it at own your risk. | |
61 | + * The returned configuration may then be used for an arbitary | |
62 | + * amount of times and even in parallel as long as a separate struct | |
63 | + * ts_state variable is provided to every instance. | |
61 | 64 | * |
62 | 65 | * The actual search is performed by either calling textsearch_find_- |
63 | 66 | * continuous() for linear data or by providing an own get_next_block() |
... | ... | @@ -89,7 +92,6 @@ |
89 | 92 | * panic("Oh my god, dancing chickens at %d\n", pos); |
90 | 93 | * |
91 | 94 | * textsearch_destroy(conf); |
92 | - * | |
93 | 95 | * ========================================================================== |
94 | 96 | */ |
95 | 97 | |
... | ... | @@ -279,7 +281,7 @@ |
279 | 281 | if (ops == NULL) |
280 | 282 | goto errout; |
281 | 283 | |
282 | - conf = ops->init(pattern, len, gfp_mask); | |
284 | + conf = ops->init(pattern, len, gfp_mask, flags); | |
283 | 285 | if (IS_ERR(conf)) { |
284 | 286 | err = PTR_ERR(conf); |
285 | 287 | goto errout; |