Changeset 1757


Ignore:
Timestamp:
Jan 26, 2008 10:45:52 AM (16 years ago)
Author:
bennylp
Message:

Added pj_strstr() and pj_stristr() in pjlib

Location:
pjproject/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/include/pj/string.h

    r1397 r1757  
    473473 
    474474/** 
     475 * Find the occurence of a substring substr in string str. 
     476 * 
     477 * @param str       The string to search. 
     478 * @param substr    The string to search fo. 
     479 * 
     480 * @return the pointer to the position of substr in str, or NULL. Note 
     481 *         that if str is not NULL terminated, the returned pointer 
     482 *         is pointing to non-NULL terminated string. 
     483 */ 
     484PJ_DECL(char*) pj_strstr(const pj_str_t *str, const pj_str_t *substr); 
     485 
     486/** 
     487 * Performs substring lookup like pj_strstr() but ignores the case of 
     488 * both strings. 
     489 * 
     490 * @param str       The string to search. 
     491 * @param substr    The string to search fo. 
     492 * 
     493 * @return the pointer to the position of substr in str, or NULL. Note 
     494 *         that if str is not NULL terminated, the returned pointer 
     495 *         is pointing to non-NULL terminated string. 
     496 */ 
     497PJ_DECL(char*) pj_stristr(const pj_str_t *str, const pj_str_t *substr); 
     498 
     499/** 
    475500 * Remove (trim) leading whitespaces from the string. 
    476501 * 
  • pjproject/trunk/pjlib/src/pj/string.c

    r1210 r1757  
    2727#  include <pj/string_i.h> 
    2828#endif 
     29 
     30 
     31PJ_DEF(char*) pj_strstr(const pj_str_t *str, const pj_str_t *substr) 
     32{ 
     33    const char *s, *ends; 
     34 
     35    /* Special case when substr is zero */ 
     36    if (substr->slen == 0) { 
     37        return (char*)str->ptr; 
     38    } 
     39 
     40    s = str->ptr; 
     41    ends = str->ptr + str->slen - substr->slen; 
     42    for (; s<=ends; ++s) { 
     43        if (pj_ansi_strncmp(s, substr->ptr, substr->slen)==0) 
     44            return (char*)s; 
     45    } 
     46    return NULL; 
     47} 
     48 
     49 
     50PJ_DEF(char*) pj_stristr(const pj_str_t *str, const pj_str_t *substr) 
     51{ 
     52    const char *s, *ends; 
     53 
     54    /* Special case when substr is zero */ 
     55    if (substr->slen == 0) { 
     56        return (char*)str->ptr; 
     57    } 
     58 
     59    s = str->ptr; 
     60    ends = str->ptr + str->slen - substr->slen; 
     61    for (; s<=ends; ++s) { 
     62        if (pj_ansi_strnicmp(s, substr->ptr, substr->slen)==0) 
     63            return (char*)s; 
     64    } 
     65    return NULL; 
     66} 
    2967 
    3068 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c

    r1745 r1757  
    254254 
    255255    return PJSUA_INVALID_ID; 
    256 } 
    257  
    258 static pj_bool_t pj_stristr(const pj_str_t *str, const pj_str_t *substr) 
    259 { 
    260     int i; 
    261  
    262     for (i=0; i<=(str->slen-substr->slen); ++i) { 
    263         pj_str_t s; 
    264         s.ptr = str->ptr+i; 
    265         s.slen = substr->slen; 
    266  
    267         if (pj_stricmp(&s, substr)==0) 
    268             return PJ_TRUE; 
    269     } 
    270     return PJ_FALSE; 
    271256} 
    272257 
Note: See TracChangeset for help on using the changeset viewer.