home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / lib / libc / src / strstr.c < prev   
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.9 KB  |  105 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "plstr.h"
  20.  
  21. PR_IMPLEMENT(char *)
  22. PL_strstr(const char *big, const char *little)
  23. {
  24.     PRUint32 ll;
  25.  
  26.     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
  27.     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
  28.  
  29.     ll = PL_strlen(little);
  30.  
  31.     for( ; *big; big++ )
  32.         if( *little == *big )
  33.             if( 0 == PL_strncmp(big, little, ll) )
  34.                 return (char *)big;
  35.  
  36.     return (char *)0;
  37. }
  38.  
  39. PR_IMPLEMENT(char *)
  40. PL_strrstr(const char *big, const char *little)
  41. {
  42.     const char *p;
  43.     PRUint32 ll;
  44.  
  45.     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
  46.     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
  47.  
  48.     ll = PL_strlen(little);
  49.     p = &big[ PL_strlen(big) - ll ];
  50.     if( p < big ) return (char *)0;
  51.  
  52.     for( ; p >= big; p-- )
  53.         if( *little == *p )
  54.             if( 0 == PL_strncmp(p, little, ll) )
  55.                 return (char *)p;
  56.  
  57.     return (char *)0;
  58. }
  59.  
  60. PR_IMPLEMENT(char *)
  61. PL_strnstr(const char *big, const char *little, PRUint32 max)
  62. {
  63.     PRUint32 ll;
  64.  
  65.     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
  66.     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
  67.  
  68.     ll = PL_strlen(little);
  69.     if( ll > max ) return (char *)0;
  70.     max -= ll;
  71.     max++;
  72.  
  73.     for( ; *big && max; big++, max-- )
  74.         if( *little == *big )
  75.             if( 0 == PL_strncmp(big, little, ll) )
  76.                 return (char *)big;
  77.  
  78.     return (char *)0;
  79. }
  80.  
  81. PR_IMPLEMENT(char *)
  82. PL_strnrstr(const char *big, const char *little, PRUint32 max)
  83. {
  84.     const char *p;
  85.     PRUint32 ll;
  86.  
  87.     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
  88.     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
  89.  
  90.     ll = PL_strlen(little);
  91.  
  92.     for( p = big; *p && max; p++, max-- )
  93.         ;
  94.  
  95.     p -= ll;
  96.     if( p < big ) return (char *)0;
  97.  
  98.     for( ; p >= big; p-- )
  99.         if( *little == *p )
  100.             if( 0 == PL_strncmp(p, little, ll) )
  101.                 return (char *)p;
  102.  
  103.     return (char *)0;
  104. }
  105.