add function fc_split_string and fc_match_delim

pull/37/head
yuqing 2018-08-20 18:11:18 +08:00
parent 15526c7277
commit 94741c51c2
5 changed files with 87 additions and 8 deletions

View File

@ -3,6 +3,7 @@ Version 1.40 2018-08-20
* add function conn_pool_parse_server_info and conn_pool_load_server_info
* support directive: #@add_annotation, for example:
#@add_annotation CONFIG_GET /usr/lib/libshmcache.so /etc/libshmcache.conf
* add function fc_split_string and fc_match_delim
Version 1.39 2018-07-31
* add #@function REPLACE_VARS

View File

@ -840,7 +840,7 @@ static int iniAddAnnotation(char *params)
int result;
trim(params);
count = splitEx(params, ' ', cols, MAX_PARAMS);
count = fc_split_string(params, " \t", cols, MAX_PARAMS);
if (count < 2)
{
logError("file: "__FILE__", line: %d, "
@ -987,6 +987,7 @@ static int iniDoLoadItemsFromBuffer(char *content, IniContext *pContext)
isAnnotation = 0;
}
STR_TRIM(pLine);
if (*pLine == '#' && \
strncasecmp(pLine+1, "include", 7) == 0 && \
(*(pLine+8) == ' ' || *(pLine+8) == '\t'))
@ -1091,8 +1092,7 @@ static int iniDoLoadItemsFromBuffer(char *content, IniContext *pContext)
continue;
}
STR_TRIM(pLine);
if (*pLine == '#' || *pLine == '\0')
if (*pLine == '\0')
{
continue;
}

View File

@ -747,6 +747,59 @@ int splitEx(char *src, const char seperator, char **pCols, const int nMaxCols)
return count;
}
bool fc_match_delim(const char *str, const char *delim)
{
const char *sp;
const char *send;
const char *dp;
const char *dend;
send = str + strlen(str);
dend = delim + strlen(delim);
for (sp=str; sp<send; sp++)
{
for (dp=delim; dp<dend; dp++)
{
if (*sp == *dp)
{
break;
}
}
if (dp == dend)
{
return false;
}
}
return true;
}
int fc_split_string(char *src, const char *delim, char **pCols, const int nMaxCols)
{
char *token;
char *stringp;
int count = 0;
stringp = src;
while ((token=strsep(&stringp, delim)) != NULL)
{
if (count >= nMaxCols)
{
break;
}
if (fc_match_delim(token, delim))
{
continue;
}
pCols[count++] = token;
}
return count;
}
int my_strtok(char *src, const char *delim, char **pCols, const int nMaxCols)
{
char *p;

View File

@ -366,6 +366,25 @@ void freeSplit(char **p);
*/
int splitEx(char *src, const char seperator, char **pCols, const int nMaxCols);
/** split string by delimiter characters
* parameters:
* src: the source string, will be modified by this function
* delim: the delimiter characters
* pCols: store split strings
* nMaxCols: max columns (max split count)
* return: string array / column count
*/
int fc_split_string(char *src, const char *delim, char **pCols, const int nMaxCols);
/** if the input string contains all delimiter characters
* parameters:
* str: the input string
* delim: the delimiter characters
* return: true for contains all delimiter characters, otherwise false
*/
bool fc_match_delim(const char *str, const char *delim);
/** split string
* parameters:
* src: the source string, will be modified by this function

View File

@ -1,13 +1,19 @@
#@set author_name = yuqing
#@set OS_NAME = $(uname -a | awk '{print $1;}')
# to support #@function CONFIG_GET
# the version of libshmcache >= 1.0.7
#@add_annotation CONFIG_GET /usr/local/lib/libshmcache.so /usr/local/etc/libshmcache.conf
#@if %{OS_NAME} in [Darwin]
#@add_annotation CONFIG_GET /usr/local/lib/libshmcache.so /usr/local/etc/libshmcache.conf
#@else
#@add_annotation CONFIG_GET /usr/lib/libshmcache.so /etc/libshmcache.conf
#@endif
#@function CONFIG_GET
app.version = app1.key1
#@set author_name = yuqing
#@set os_name = $(uname -a | awk '{print $1;}')
#@function SHELL_EXEC
host = hostname
@ -17,7 +23,7 @@ bind_ip = inner[0]
#@function EXPRESS_CALC
thread_count = 5 * 4 + 6
#@if %{os_name} in [Linux, Darwin]
#@if %{OS_NAME} in [Linux, Darwin]
[AccessLogSpaceCharConvert]
# format: src = dest
# src can be a printable char or a backslash char pair such as \t