summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pjlib/include/pj/string.h25
-rw-r--r--pjlib/src/pj/string.c38
-rw-r--r--pjsip/src/pjsua-lib/pjsua_call.c15
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
@@ -472,6 +472,31 @@ PJ_INLINE(char*) pj_strchr( const pj_str_t *str, int chr)
}
/**
+ * 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.
*
* @param str 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