From f93f4b87a492ba5dff2854813463ca6fc419b393 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Sat, 26 Jan 2008 10:45:52 +0000 Subject: Added pj_strstr() and pj_stristr() in pjlib git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1757 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/include/pj/string.h | 25 +++++++++++++++++++++++++ pjlib/src/pj/string.c | 38 ++++++++++++++++++++++++++++++++++++++ pjsip/src/pjsua-lib/pjsua_call.c | 15 --------------- 3 files changed, 63 insertions(+), 15 deletions(-) diff --git a/pjlib/include/pj/string.h b/pjlib/include/pj/string.h index 8124539f..945af2da 100644 --- a/pjlib/include/pj/string.h +++ b/pjlib/include/pj/string.h @@ -471,6 +471,31 @@ PJ_INLINE(char*) pj_strchr( const pj_str_t *str, int chr) return (char*) memchr((char*)str->ptr, chr, str->slen); } +/** + * Find the occurence of a substring substr in string str. + * + * @param str The string to search. + * @param substr The string to search fo. + * + * @return the pointer to the position of substr in str, or NULL. Note + * that if str is not NULL terminated, the returned pointer + * is pointing to non-NULL terminated string. + */ +PJ_DECL(char*) pj_strstr(const pj_str_t *str, const pj_str_t *substr); + +/** + * Performs substring lookup like pj_strstr() but ignores the case of + * both strings. + * + * @param str The string to search. + * @param substr The string to search fo. + * + * @return the pointer to the position of substr in str, or NULL. Note + * that if str is not NULL terminated, the returned pointer + * is pointing to non-NULL terminated string. + */ +PJ_DECL(char*) pj_stristr(const pj_str_t *str, const pj_str_t *substr); + /** * Remove (trim) leading whitespaces from the string. * diff --git a/pjlib/src/pj/string.c b/pjlib/src/pj/string.c index 9a2ca0f2..fb520c7b 100644 --- a/pjlib/src/pj/string.c +++ b/pjlib/src/pj/string.c @@ -28,6 +28,44 @@ #endif +PJ_DEF(char*) pj_strstr(const pj_str_t *str, const pj_str_t *substr) +{ + const char *s, *ends; + + /* Special case when substr is zero */ + if (substr->slen == 0) { + return (char*)str->ptr; + } + + s = str->ptr; + ends = str->ptr + str->slen - substr->slen; + for (; s<=ends; ++s) { + if (pj_ansi_strncmp(s, substr->ptr, substr->slen)==0) + return (char*)s; + } + return NULL; +} + + +PJ_DEF(char*) pj_stristr(const pj_str_t *str, const pj_str_t *substr) +{ + const char *s, *ends; + + /* Special case when substr is zero */ + if (substr->slen == 0) { + return (char*)str->ptr; + } + + s = str->ptr; + ends = str->ptr + str->slen - substr->slen; + for (; s<=ends; ++s) { + if (pj_ansi_strnicmp(s, substr->ptr, substr->slen)==0) + return (char*)s; + } + return NULL; +} + + PJ_DEF(pj_str_t*) pj_strltrim( pj_str_t *str ) { register char *p = str->ptr; diff --git a/pjsip/src/pjsua-lib/pjsua_call.c b/pjsip/src/pjsua-lib/pjsua_call.c index f4e90aa8..8638a806 100644 --- a/pjsip/src/pjsua-lib/pjsua_call.c +++ b/pjsip/src/pjsua-lib/pjsua_call.c @@ -255,21 +255,6 @@ static pjsua_call_id alloc_call_id(void) return PJSUA_INVALID_ID; } -static pj_bool_t pj_stristr(const pj_str_t *str, const pj_str_t *substr) -{ - int i; - - for (i=0; i<=(str->slen-substr->slen); ++i) { - pj_str_t s; - s.ptr = str->ptr+i; - s.slen = substr->slen; - - if (pj_stricmp(&s, substr)==0) - return PJ_TRUE; - } - return PJ_FALSE; -} - /* Get signaling secure level. * Return: * 0: if signaling is not secure -- cgit v1.2.3