使用pcre2替代glib从中的regex进行替换。

This commit is contained in:
zhengchao
2018-09-27 19:06:57 +08:00
parent 20c55b74d8
commit 5e6dde5e51
9 changed files with 731 additions and 261 deletions

View File

@@ -0,0 +1,45 @@
#include "pattern_replace.h"
#include <sys/types.h>//fstat
#include <sys/ioctl.h>
#include <string.h>
#include <stdio.h>
#include <gtest/gtest.h>
TEST(PatternReplace, Pure)
{
const char* filename="./test_data/facebook_index.html";
const char* exec_para="zone=http_resp_body;substitute=/添加手机号/Mobile\bPhone";
size_t n_got_rule=0;
struct replace_rule rules[16];
n_got_rule=format_replace_rule(exec_para, rules, sizeof(rules)/sizeof(rules[0]));
EXPECT_EQ(n_got_rule, 1);
FILE* fp=NULL;
struct stat file_info;
stat(filename, &file_info);
size_t file_size=file_info.st_size;
fp=fopen(filename,"r");
ASSERT_FALSE(fp==NULL);
if(fp==NULL)
{
return;
}
char* file_buff=(char*)malloc(file_size);
fread(file_buff,1,file_size,fp);
fclose(fp);
struct evbuffer* output=NULL;
output=execute_replace_rule(file_buff, file_size, kZoneResponseBody, rules,n_got_rule);
EXPECT_FALSE(output==NULL);
return;
}
int main(int argc, char ** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}