Back to index

lightning-sunbird  0.9+nobinonly
Functions
plstr.h File Reference
#include "prtypes.h"

Go to the source code of this file.

Functions

PR_BEGIN_EXTERN_C PL_strlen (const char *str)
 PL_strnlen (const char *str, PRUint32 max)
 PL_strcpy (char *dest, const char *src)
 PL_strncpy (char *dest, const char *src, PRUint32 max)
 PL_strncpyz (char *dest, const char *src, PRUint32 max)
 PL_strdup (const char *s)
 PL_strfree (char *s)
 PL_strndup (const char *s, PRUint32 max)
 PL_strcat (char *dst, const char *src)
 PL_strncat (char *dst, const char *src, PRUint32 max)
 PL_strcatn (char *dst, PRUint32 max, const char *src)
 PL_strcmp (const char *a, const char *b)
 PL_strncmp (const char *a, const char *b, PRUint32 max)
 PL_strcasecmp (const char *a, const char *b)
 PL_strncasecmp (const char *a, const char *b, PRUint32 max)
 PL_strchr (const char *s, char c)
 PL_strrchr (const char *s, char c)
 PL_strnchr (const char *s, char c, PRUint32 n)
 PL_strnrchr (const char *s, char c, PRUint32 n)
 PL_strpbrk (const char *s, const char *list)
 PL_strprbrk (const char *s, const char *list)
 PL_strnpbrk (const char *s, const char *list, PRUint32 n)
 PL_strnprbrk (const char *s, const char *list, PRUint32 n)
 PL_strstr (const char *big, const char *little)
 PL_strrstr (const char *big, const char *little)
 PL_strnstr (const char *big, const char *little, PRUint32 n)
 PL_strnrstr (const char *big, const char *little, PRUint32 max)
 PL_strcasestr (const char *big, const char *little)
 PL_strcaserstr (const char *big, const char *little)
 PL_strncasestr (const char *big, const char *little, PRUint32 max)
 PL_strncaserstr (const char *big, const char *little, PRUint32 max)
 PL_strtok_r (char *s1, const char *s2, char **lasts)

Function Documentation

PL_strcasecmp ( const char *  a,
const char *  b 
)

Definition at line 77 of file strccmp.c.

{
    const unsigned char *ua = (const unsigned char *)a;
    const unsigned char *ub = (const unsigned char *)b;

    if( ((const char *)0 == a) || (const char *)0 == b ) 
        return (PRIntn)(a-b);

    while( (uc[*ua] == uc[*ub]) && ('\0' != *a) )
    {
        a++;
        ua++;
        ub++;
    }

    return (PRIntn)(uc[*ua] - uc[*ub]);
}
PL_strcaserstr ( const char *  big,
const char *  little 
)

Definition at line 59 of file strcstr.c.

{
    const char *p;
    PRUint32 ll;

    if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
    if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;

    ll = PL_strlen(little);
    p = &big[ PL_strlen(big) - ll ];
    if( p < big ) return (char *)0;

    for( ; p >= big; p-- )
        /* obvious improvement available here */
            if( 0 == PL_strncasecmp(p, little, ll) )
                return (char *)p;

    return (char *)0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PL_strcasestr ( const char *  big,
const char *  little 
)

Definition at line 41 of file strcstr.c.

{
    PRUint32 ll;

    if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
    if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;

    ll = PL_strlen(little);

    for( ; *big; big++ )
        /* obvious improvement available here */
            if( 0 == PL_strncasecmp(big, little, ll) )
                return (char *)big;

    return (char *)0;
}

Here is the call graph for this function:

PL_strcat ( char *  dst,
const char *  src 
)

Definition at line 42 of file strcat.c.

{
    if( ((char *)0 == dest) || ((const char *)0 == src) )
        return dest;

    return strcat(dest, src);
}

Here is the caller graph for this function:

PL_strcatn ( char *  dst,
PRUint32  max,
const char *  src 
)

Definition at line 66 of file strcat.c.

{
    char *rv;
    PRUint32 dl;

    if( ((char *)0 == dest) || ((const char *)0 == src) )
        return dest;

    for( rv = dest, dl = 0; *dest; dest++, dl++ )
        ;

    if( max <= dl ) return rv;
    (void)PL_strncpyz(dest, src, max-dl);

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PL_strchr ( const char *  s,
char  c 
)

Definition at line 42 of file strchr.c.

{
    if( (const char *)0 == s ) return (char *)0;

    return strchr(s, c);
}

Here is the call graph for this function:

PL_strcmp ( const char *  a,
const char *  b 
)

Definition at line 42 of file strcmp.c.

{
    if( ((const char *)0 == a) || (const char *)0 == b ) 
        return (PRIntn)(a-b);

    return (PRIntn)strcmp(a, b);
}
PL_strcpy ( char *  dest,
const char *  src 
)

Definition at line 42 of file strcpy.c.

{
    if( ((char *)0 == dest) || ((const char *)0 == src) ) return (char *)0;

    return strcpy(dest, src);
}
PL_strdup ( const char *  s)

Definition at line 43 of file strdup.c.

{
    char *rv;
    size_t n;

    if( (const char *)0 == s )
        s = "";

    n = strlen(s) + 1;

    rv = (char *)malloc(n);
    if( (char *)0 == rv ) return rv;

    (void)memcpy(rv, s, n);

    return rv;
}

Here is the call graph for this function:

PL_strfree ( char *  s)

Definition at line 62 of file strdup.c.

{
    free(s);
}

Definition at line 44 of file strlen.c.

{
    size_t l;

    if( (const char *)0 == str ) return 0;

    l = strlen(str);

    /* error checking in case we have a 64-bit platform -- make sure
     * we don't have ultra long strings that overflow an int32
     */ 
    if( sizeof(PRUint32) < sizeof(size_t) )
        PR_ASSERT(l < 2147483647);

    return (PRUint32)l;
}
PL_strncasecmp ( const char *  a,
const char *  b,
PRUint32  max 
)

Definition at line 96 of file strccmp.c.

{
    const unsigned char *ua = (const unsigned char *)a;
    const unsigned char *ub = (const unsigned char *)b;

    if( ((const char *)0 == a) || (const char *)0 == b ) 
        return (PRIntn)(a-b);

    while( max && (uc[*ua] == uc[*ub]) && ('\0' != *a) )
    {
        a++;
        ua++;
        ub++;
        max--;
    }

    if( 0 == max ) return (PRIntn)0;

    return (PRIntn)(uc[*ua] - uc[*ub]);
}
PL_strncaserstr ( const char *  big,
const char *  little,
PRUint32  max 
)

Definition at line 101 of file strcstr.c.

{
    const char *p;
    PRUint32 ll;

    if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
    if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;

    ll = PL_strlen(little);

    for( p = big; max && *p; p++, max-- )
        ;

    p -= ll;
    if( p < big ) return (char *)0;

    for( ; p >= big; p-- )
        /* obvious improvement available here */
            if( 0 == PL_strncasecmp(p, little, ll) )
                return (char *)p;

    return (char *)0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PL_strncasestr ( const char *  big,
const char *  little,
PRUint32  max 
)

Definition at line 80 of file strcstr.c.

{
    PRUint32 ll;

    if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
    if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;

    ll = PL_strlen(little);
    if( ll > max ) return (char *)0;
    max -= ll;
    max++;

    for( ; max && *big; big++, max-- )
        /* obvious improvement available here */
            if( 0 == PL_strncasecmp(big, little, ll) )
                return (char *)big;

    return (char *)0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PL_strncat ( char *  dst,
const char *  src,
PRUint32  max 
)

Definition at line 51 of file strcat.c.

{
    char *rv;

    if( ((char *)0 == dest) || ((const char *)0 == src) || (0 == max) )
        return dest;

    for( rv = dest; *dest; dest++ )
        ;

    (void)PL_strncpy(dest, src, max);
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PL_strnchr ( const char *  s,
char  c,
PRUint32  n 
)

Definition at line 58 of file strchr.c.

{
    if( (const char *)0 == s ) return (char *)0;

    for( ; n && *s; s++, n-- )
        if( *s == c )
            return (char *)s;

    if( ((char)0 == c) && (n > 0) && ((char)0 == *s) ) return (char *)s;

    return (char *)0;
}

Here is the caller graph for this function:

PL_strncmp ( const char *  a,
const char *  b,
PRUint32  max 
)

Definition at line 51 of file strcmp.c.

{
    if( ((const char *)0 == a) || (const char *)0 == b ) 
        return (PRIntn)(a-b);

    return (PRIntn)strncmp(a, b, (size_t)max);
}
PL_strncpy ( char *  dest,
const char *  src,
PRUint32  max 
)

Definition at line 50 of file strcpy.c.

{
    char *rv;
    
    if( (char *)0 == dest ) return (char *)0;
    if( (const char *)0 == src ) return (char *)0;

    for( rv = dest; max && ((*dest = *src) != 0); dest++, src++, max-- )
        ;

#ifdef JLRU
    /* XXX I (wtc) think the -- and ++ operators should be postfix. */
    while( --max )
        *++dest = '\0';
#endif /* JLRU */

    return rv;
}

Here is the caller graph for this function:

PL_strncpyz ( char *  dest,
const char *  src,
PRUint32  max 
)

Definition at line 70 of file strcpy.c.

{
    char *rv;
    
    if( (char *)0 == dest ) return (char *)0;
    if( (const char *)0 == src ) return (char *)0;
    if( 0 == max ) return (char *)0;

    for( rv = dest, max--; max && ((*dest = *src) != 0); dest++, src++, max-- )
        ;

    *dest = '\0';

    return rv;
}

Here is the caller graph for this function:

PL_strndup ( const char *  s,
PRUint32  max 
)

Definition at line 68 of file strdup.c.

{
    char *rv;
    size_t l;

    if( (const char *)0 == s )
        s = "";

    l = PL_strnlen(s, max);

    rv = (char *)malloc(l+1);
    if( (char *)0 == rv ) return rv;

    (void)memcpy(rv, s, l);
    rv[l] = '\0';

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PL_strnlen ( const char *  str,
PRUint32  max 
)

Definition at line 62 of file strlen.c.

{
    register const char *s;

    if( (const char *)0 == str ) return 0;
    for( s = str; max && *s; s++, max-- )
        ;

    return (PRUint32)(s - str);
}

Here is the caller graph for this function:

PL_strnpbrk ( const char *  s,
const char *  list,
PRUint32  n 
)

Definition at line 69 of file strpbrk.c.

{
    const char *p;

    if( ((const char *)0 == s) || ((const char *)0 == list) ) return (char *)0;

    for( ; max && *s; s++, max-- )
        for( p = list; *p; p++ )
            if( *s == *p )
                return (char *)s;

    return (char *)0;
}

Here is the caller graph for this function:

PL_strnprbrk ( const char *  s,
const char *  list,
PRUint32  n 
)

Definition at line 84 of file strpbrk.c.

{
    const char *p;
    const char *r;

    if( ((const char *)0 == s) || ((const char *)0 == list) ) return (char *)0;

    for( r = s; max && *r; r++, max-- )
        ;

    for( r--; r >= s; r-- )
        for( p = list; *p; p++ )
            if( *r == *p )
                return (char *)r;

    return (char *)0;
}

Here is the caller graph for this function:

PL_strnrchr ( const char *  s,
char  c,
PRUint32  n 
)

Definition at line 72 of file strchr.c.

{
    const char *p;

    if( (const char *)0 == s ) return (char *)0;

    for( p = s; n && *p; p++, n-- )
        ;

    if( ((char)0 == c) && (n > 0) && ((char)0 == *p) ) return (char *)p;

    for( p--; p >= s; p-- )
        if( *p == c )
            return (char *)p;

    return (char *)0;
}

Here is the caller graph for this function:

PL_strnrstr ( const char *  big,
const char *  little,
PRUint32  max 
)

Definition at line 95 of file strstr.c.

{
    const char *p;
    size_t ll;

    if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
    if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;

    ll = strlen(little);

    for( p = big; max && *p; p++, max-- )
        ;

    p -= ll;
    if( p < big ) return (char *)0;

    for( ; p >= big; p-- )
        if( *little == *p )
            if( 0 == strncmp(p, little, ll) )
                return (char *)p;

    return (char *)0;
}

Here is the caller graph for this function:

PL_strnstr ( const char *  big,
const char *  little,
PRUint32  n 
)

Definition at line 74 of file strstr.c.

{
    size_t ll;

    if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
    if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;

    ll = strlen(little);
    if( ll > (size_t)max ) return (char *)0;
    max -= (PRUint32)ll;
    max++;

    for( ; max && *big; big++, max-- )
        if( *little == *big )
            if( 0 == strncmp(big, little, ll) )
                return (char *)big;

    return (char *)0;
}

Here is the caller graph for this function:

PL_strpbrk ( const char *  s,
const char *  list 
)

Definition at line 42 of file strpbrk.c.

{
    if( ((const char *)0 == s) || ((const char *)0 == list) ) return (char *)0;

    return strpbrk(s, list);
}

Here is the caller graph for this function:

PL_strprbrk ( const char *  s,
const char *  list 
)

Definition at line 50 of file strpbrk.c.

{
    const char *p;
    const char *r;

    if( ((const char *)0 == s) || ((const char *)0 == list) ) return (char *)0;

    for( r = s; *r; r++ )
        ;

    for( r--; r >= s; r-- )
        for( p = list; *p; p++ )
            if( *r == *p )
                return (char *)r;

    return (char *)0;
}

Here is the caller graph for this function:

PL_strrchr ( const char *  s,
char  c 
)

Definition at line 50 of file strchr.c.

{
    if( (const char *)0 == s ) return (char *)0;

    return strrchr(s, c);
}

Here is the caller graph for this function:

PL_strrstr ( const char *  big,
const char *  little 
)

Definition at line 51 of file strstr.c.

{
    const char *p;
    size_t ll;
    size_t bl;

    if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
    if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;

    ll = strlen(little);
    bl = strlen(big);
    if( bl < ll ) return (char *)0;
    p = &big[ bl - ll ];

    for( ; p >= big; p-- )
        if( *little == *p )
            if( 0 == strncmp(p, little, ll) )
                return (char *)p;

    return (char *)0;
}

Here is the caller graph for this function:

PL_strstr ( const char *  big,
const char *  little 
)

Definition at line 42 of file strstr.c.

{
    if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
    if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;

    return strstr(big, little);
}

Here is the caller graph for this function:

PL_strtok_r ( char *  s1,
const char *  s2,
char **  lasts 
)

Definition at line 42 of file strtok.c.

{
    const char *sepp;
    int         c, sc;
    char       *tok;

    if( s1 == NULL )
    {
        if( *lasts == NULL )
            return NULL;

        s1 = *lasts;
    }
  
    for( ; (c = *s1) != 0; s1++ )
    {
        for( sepp = s2 ; (sc = *sepp) != 0 ; sepp++ )
        {
            if( c == sc )
                break;
        }
        if( sc == 0 )
            break; 
    }

    if( c == 0 )
    {
        *lasts = NULL;
        return NULL;
    }
  
    tok = s1++;

    for( ; (c = *s1) != 0; s1++ )
    {
        for( sepp = s2; (sc = *sepp) != 0; sepp++ )
        {
            if( c == sc )
            {
                *s1++ = '\0';
                *lasts = s1;
                return tok;
            }
        }
    }
    *lasts = NULL;
    return tok;
}

Here is the caller graph for this function: