add function fc_memmem

pull/37/head
YuQing 2018-09-27 10:12:24 +08:00
parent 6ef844bd6b
commit ea74bac9d0
4 changed files with 51 additions and 6 deletions

View File

@ -1,11 +1,12 @@
Version 1.40 2018-08-27 Version 1.40 2018-09-27
* add function conn_pool_parse_server_info and conn_pool_load_server_info * add function conn_pool_parse_server_info and conn_pool_load_server_info
* support directive: #@add_annotation, for example: * support directive: #@add_annotation, for example:
#@add_annotation CONFIG_GET /usr/lib/libshmcache.so /etc/libshmcache.conf #@add_annotation CONFIG_GET /usr/lib/libshmcache.so /etc/libshmcache.conf
* add function fc_split_string and fc_match_delim * add function fc_split_string and fc_match_delim
* add json_parser.[hc] for parse json array and map * add json_parser.[hc] for parse json array and map
* add function fc_strdup * add function fc_strdup
* add function fc_memmem
Version 1.39 2018-07-31 Version 1.39 2018-07-31
* add #@function REPLACE_VARS * add #@function REPLACE_VARS

View File

@ -81,15 +81,15 @@ extern int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int kind);
#define USE_SENDFILE #define USE_SENDFILE
#endif #endif
#define MAX_PATH_SIZE 256 #define MAX_PATH_SIZE 256
#define LOG_FILE_DIR "logs" #define LOG_FILE_DIR "logs"
#define CONF_FILE_DIR "conf" #define CONF_FILE_DIR "conf"
#define DEFAULT_CONNECT_TIMEOUT 30 #define DEFAULT_CONNECT_TIMEOUT 30
#define DEFAULT_NETWORK_TIMEOUT 30 #define DEFAULT_NETWORK_TIMEOUT 30
#define DEFAULT_MAX_CONNECTONS 256 #define DEFAULT_MAX_CONNECTONS 1024
#define DEFAULT_WORK_THREADS 4 #define DEFAULT_WORK_THREADS 4
#define SYNC_LOG_BUFF_DEF_INTERVAL 10 #define SYNC_LOG_BUFF_DEF_INTERVAL 10
#define TIME_NONE -1 #define TIME_NONE -1
#define IP_ADDRESS_SIZE 16 #define IP_ADDRESS_SIZE 16
#define INFINITE_FILE_SIZE (256 * 1024LL * 1024 * 1024 * 1024 * 1024LL) #define INFINITE_FILE_SIZE (256 * 1024LL * 1024 * 1024 * 1024 * 1024LL)
@ -232,6 +232,12 @@ typedef void* (*MallocFunc)(size_t size);
(dest).len = strlen(src); \ (dest).len = strlen(src); \
} while (0) } while (0)
#define FC_SET_STRING_EX(dest, src, len) \
do { \
(dest).str = src; \
(dest).len = len; \
} while (0)
#define FC_SET_STRING_NULL(dest) \ #define FC_SET_STRING_NULL(dest) \
do { \ do { \
(dest).str = NULL; \ (dest).str = NULL; \

View File

@ -2781,3 +2781,33 @@ char *fc_strdup(const char *str, const int len)
*(output + len) = '\0'; *(output + len) = '\0';
return output; return output;
} }
const char *fc_memmem(const string_t *str, const string_t *needle)
{
const char *ps;
const char *last;
const char *pn;
const char *nend;
int loop;
int i;
loop = str->len - needle->len;
if (loop < 0) {
return NULL;
}
last = str->str + loop;
nend = needle->str + needle->len;
for (ps=str->str; ps<=last; ps++) {
for (pn=needle->str,i=0; pn<nend; pn++,i++) {
if (*pn != *(ps + i)) {
break;
}
}
if (pn == nend) {
return ps;
}
}
return NULL;
}

View File

@ -824,6 +824,14 @@ bool ends_with(const char *str, const char *needle);
*/ */
char *fc_strdup(const char *str, const int len); char *fc_strdup(const char *str, const int len);
/** memmem
* parameters:
* str: the string to match
* needle: the needle string
* return: the matched string, NULL for fail
*/
const char *fc_memmem(const string_t *str, const string_t *needle);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif