add test_char_convert_loader.c
parent
2d123299a9
commit
beab8dad5a
|
|
@ -19,7 +19,7 @@
|
||||||
int char_convert_loader_init(FastCharConverter *pCharConverter,
|
int char_convert_loader_init(FastCharConverter *pCharConverter,
|
||||||
const IniItem *items, const int count)
|
const IniItem *items, const int count)
|
||||||
{
|
{
|
||||||
char_convert_loader_init(pCharConverter, NULL, 0);
|
char_converter_init(pCharConverter, NULL, 0);
|
||||||
return char_convert_loader_add(pCharConverter, items, count);
|
return char_convert_loader_add(pCharConverter, items, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,6 +85,9 @@ static int char_convert_loader_parse(const char *s, unsigned char *out_char)
|
||||||
case 's':
|
case 's':
|
||||||
*out_char = ' ';
|
*out_char = ' ';
|
||||||
break;
|
break;
|
||||||
|
case '\\':
|
||||||
|
*out_char = '\\';
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"invalid char string: %s", __LINE__, s);
|
"invalid char string: %s", __LINE__, s);
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ INC_PATH = -I/usr/include/fastcommon
|
||||||
LIB_PATH = -lfastcommon -lpthread
|
LIB_PATH = -lfastcommon -lpthread
|
||||||
|
|
||||||
ALL_PRGS = test_allocator test_skiplist test_multi_skiplist test_mblock test_blocked_queue \
|
ALL_PRGS = test_allocator test_skiplist test_multi_skiplist test_mblock test_blocked_queue \
|
||||||
test_id_generator test_ini_parser test_char_convert
|
test_id_generator test_ini_parser test_char_convert test_char_convert_loader
|
||||||
|
|
||||||
all: $(ALL_PRGS)
|
all: $(ALL_PRGS)
|
||||||
.c:
|
.c:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
|
||||||
|
[AccessLogSpaceCharConvert]
|
||||||
|
# format: src = dest
|
||||||
|
# src can be a printable char or a backslash char pair such as \t
|
||||||
|
# src and dest can be ASCII code as \x##, such as \x20 for the SPACE char
|
||||||
|
|
||||||
|
# dest can be a printable char, ASCII code as \x##,
|
||||||
|
# or quoted two chars as backslash follow by a char, such as "\t"
|
||||||
|
|
||||||
|
# extended backslash char pairs:
|
||||||
|
# \0 for the ASCII 0 character
|
||||||
|
# \s for the SPACE character
|
||||||
|
|
||||||
|
\0 = "\0"
|
||||||
|
\t = "\t"
|
||||||
|
\n = "\n"
|
||||||
|
\v = "\v"
|
||||||
|
\f = "\f"
|
||||||
|
\r = "\r"
|
||||||
|
\s = "\s"
|
||||||
|
\\ = "\\"
|
||||||
|
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include "logger.h"
|
||||||
|
#include "ini_file_reader.h"
|
||||||
|
#include "char_convert_loader.h"
|
||||||
|
#include "char_converter.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
IniContext context;
|
||||||
|
IniItem *items;
|
||||||
|
int result;
|
||||||
|
int count;
|
||||||
|
int input_len;
|
||||||
|
int out_len;
|
||||||
|
char input[8 * 1024];
|
||||||
|
char output[10 * 1024];
|
||||||
|
FastCharConverter converter;
|
||||||
|
|
||||||
|
if (argc >= 2) {
|
||||||
|
input_len = snprintf(input, sizeof(input), "%s", argv[1]);
|
||||||
|
} else {
|
||||||
|
input_len = read(0, input, sizeof(input) - 1);
|
||||||
|
if (input_len < 0) {
|
||||||
|
fprintf(stderr, "read from stdin fail");
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
*(input + input_len) = '\0';
|
||||||
|
}
|
||||||
|
log_init();
|
||||||
|
|
||||||
|
if ((result=iniLoadFromFile("test.ini", &context)) != 0)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
iniPrintItems(&context);
|
||||||
|
|
||||||
|
printf("input_len: %d\n%s\n\n", (int)strlen(input), input);
|
||||||
|
|
||||||
|
items = iniGetSectionItems("AccessLogSpaceCharConvert", &context, &count);
|
||||||
|
result = char_convert_loader_init(&converter, items, count);
|
||||||
|
if (result != 0) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
iniFreeContext(&context);
|
||||||
|
|
||||||
|
count = fast_char_convert(&converter, input, input_len,
|
||||||
|
output, &out_len, sizeof(output));
|
||||||
|
printf("count: %d\n", count);
|
||||||
|
printf("out_len: %d\n%.*s\n", out_len, out_len, output);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in New Issue