-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
106 lines (95 loc) · 2.21 KB
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "word_filter.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
char *usecase[] = {
"helloworld",
"HelloWorld",
"Hello World!",
"hello WORLD",
"wordfilter",
"word filter",
"WORD FILTER",
"Word Filter",
"this is a test",
"screenword",
"this is a bad word.",
"first make it runs, then make it simple",
"say hello hello hello",
"hi hi hi",
"b a d w o r d!",
"我 是 屏 蔽 词!",
"我是屏蔽词!",
"我~是~屏~蔽~词~",
"我是屏蔽~词~",
"xx.XXX.com",
"..........1",
"1............",
"............",
". . .***test",
"xx .XXX.com",
".屏蔽词",
"屏蔽xx"
};
char *badword[] = {
"bad",
"word",
"is",
"simple",
"filter",
"hi",
"hello",
"aa",
"bb",
"cc",
"屏蔽词",
"词",
"屏蔽",
"xx.XXX.com"
};
int main(int argc, char **argv) {
wordfilterctxptr ctx = wf_create_ctx();
wf_set_ignore_case(ctx, 1);
for (int i = 0; i < sizeof(badword)/sizeof(*badword); i++) {
wf_insert_word(ctx, badword[i]);
}
wf_insert_skip_word(ctx, "*");
wf_insert_skip_word(ctx, " ");
wf_insert_skip_word(ctx, ".");
printf("------------test \"wf_search_word_ex\":\n");
for (int i = 0; i < sizeof(usecase)/sizeof(*usecase); i++) {
printf("usecase[%d]:%s\n", i, usecase[i]);
strnodeptr strlist;
wf_search_word_ex(ctx, usecase[i], &strlist);
strnodeptr p = strlist;
while (p) {
printf("bad word:%s\n", p->str);
p = p->next;
}
wf_free_str_list(strlist);
}
printf("------------test \"wf_filter_word\":\n");
for (int i = 0; i < sizeof(usecase)/sizeof(*usecase); i++) {
printf("usecase[%d]:%s\n", i, usecase[i]);
strnodeptr strlist;
size_t slen = strlen(usecase[i]) + 1;
char newstr[slen];
memset(newstr, 0, slen);
wf_filter_word(ctx, usecase[i], &strlist, newstr);
printf("newstr:%s\n", newstr);
strnodeptr p = strlist;
while (p) {
printf("bad word:%s\n", p->str);
p = p->next;
}
wf_free_str_list(strlist);
}
char string[255 + 1] = {0};
wf_search_word(ctx, "...屏...蔽...", string);
printf("test:%s", string);
wf_clean_ctx(ctx);
wf_free_ctx(ctx);
//memory leak check
printf("memroy alloc size:%llu\n", wf_get_memsize());
return 0;
}