static void test2(void) { ACL_TOKEN *tree; ACL_TOKEN *token; const char *n1 = "名称1", *n2 = "名称2", *n3 = "名称3"; const char *v1 = "变量1", *v2 = "变量2", *v3 = "变量3"; const char *s = "中国人民名称1,在这个世界上,你在哪儿名称2? " "我不知道你的名称,你能告诉我吗?我的名称3是..."; const char *p = s; if (1) { tree = acl_token_tree_create(NULL); acl_token_tree_add(tree, n1, ACL_TOKEN_F_STOP, v1); acl_token_tree_add(tree, n2, ACL_TOKEN_F_STOP, v2); acl_token_tree_add(tree, n3, ACL_TOKEN_F_STOP, v3); } else tree = acl_token_tree_create("名称1|p 名称2|p 名称3|p"); printf("-----------------------------------\n"); acl_token_tree_print(tree); token = acl_token_tree_word_match(tree, "名称1"); if (token) printf("find, %s: %s\n", acl_token_name1(token), (const char*) token->ctx); else printf("no find\n"); printf("-----------------------------------\n"); while (*p) { token = acl_token_tree_match(tree, &p, NULL, NULL); if (token == NULL) break; printf("%s: %s\n", acl_token_name1(token), (const char*) token->ctx); } printf("-----------------------------------\n"); acl_token_tree_destroy(tree); }
void acl_xml3_tag_add(const char *tag) { if (tag_tree) { char buf[256]; ACL_SAFE_STRNCPY(buf, tag, sizeof(buf)); acl_lowercase(buf); acl_token_tree_add(tag_tree, buf, ACL_TOKEN_F_STOP, NULL); } }
static void xml_decode_init(void) { int i; __token_tree = acl_token_new(); for (i = 0; __tab[i].str != 0; i++) acl_token_tree_add(__token_tree, __tab[i].txt, ACL_TOKEN_F_STOP, &__tab[i]); /* 进程退出时调用 html_decode_free 释放内存资源 */ atexit(xml_decode_free); }
ACL_TOKEN *acl_token_tree_create2(const char *s, const char *sep) { const char *myname = "acl_token_tree_create"; ACL_ARGV *argv; ACL_ITER iter; unsigned int flag; ACL_TOKEN *token_tree; const ACL_TOKEN *token; ACL_VSTRING *buf; token_tree = acl_token_new(); if (s == NULL || *s == 0) return (token_tree); buf = acl_vstring_alloc(256); argv = acl_argv_split(s, sep); acl_foreach(iter, argv) { char *word = (char*) iter.ptr; char *ptr = strchr(word, '|'); flag = ACL_TOKEN_F_STOP; if (ptr) { *ptr++ = 0; if (*ptr == 'D' || *ptr == 'd') flag |= ACL_TOKEN_F_DENY; if (*ptr == 'P' || *ptr == 'p') flag |= ACL_TOKEN_F_PASS; } token = acl_token_tree_add(token_tree, word, flag, NULL); if (token == NULL) { acl_msg_info("%s(%d): word(%s) discard", myname, __LINE__, word); } else { ACL_VSTRING_RESET(buf); acl_token_name(token, buf); /* acl_msg_info("%s(%d): add word(%s) ok, token's name(%s)", myname, __LINE__, word, STR(buf)); */ } }