andre@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: andre@0: #include "plstr.h" andre@0: #include andre@0: andre@0: PR_IMPLEMENT(char *) andre@0: PL_strstr(const char *big, const char *little) andre@0: { andre@0: if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0; andre@0: if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0; andre@0: andre@0: return strstr(big, little); andre@0: } andre@0: andre@0: PR_IMPLEMENT(char *) andre@0: PL_strrstr(const char *big, const char *little) andre@0: { andre@0: const char *p; andre@0: size_t ll; andre@0: size_t bl; andre@0: andre@0: if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0; andre@0: if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0; andre@0: andre@0: ll = strlen(little); andre@0: bl = strlen(big); andre@0: if( bl < ll ) return (char *)0; andre@0: p = &big[ bl - ll ]; andre@0: andre@0: for( ; p >= big; p-- ) andre@0: if( *little == *p ) andre@0: if( 0 == strncmp(p, little, ll) ) andre@0: return (char *)p; andre@0: andre@0: return (char *)0; andre@0: } andre@0: andre@0: PR_IMPLEMENT(char *) andre@0: PL_strnstr(const char *big, const char *little, PRUint32 max) andre@0: { andre@0: size_t ll; andre@0: andre@0: if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0; andre@0: if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0; andre@0: andre@0: ll = strlen(little); andre@0: if( ll > (size_t)max ) return (char *)0; andre@0: max -= (PRUint32)ll; andre@0: max++; andre@0: andre@0: for( ; max && *big; big++, max-- ) andre@0: if( *little == *big ) andre@0: if( 0 == strncmp(big, little, ll) ) andre@0: return (char *)big; andre@0: andre@0: return (char *)0; andre@0: } andre@0: andre@0: PR_IMPLEMENT(char *) andre@0: PL_strnrstr(const char *big, const char *little, PRUint32 max) andre@0: { andre@0: const char *p; andre@0: size_t ll; andre@0: andre@0: if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0; andre@0: if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0; andre@0: andre@0: ll = strlen(little); andre@0: andre@0: for( p = big; max && *p; p++, max-- ) andre@0: ; andre@0: andre@0: p -= ll; andre@0: if( p < big ) return (char *)0; andre@0: andre@0: for( ; p >= big; p-- ) andre@0: if( *little == *p ) andre@0: if( 0 == strncmp(p, little, ll) ) andre@0: return (char *)p; andre@0: andre@0: return (char *)0; andre@0: }