home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / lib / libc / src / strchr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.0 KB  |  84 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_strchr(const char *s, char c)
  23. {
  24.     if( (const char *)0 == s ) return (char *)0;
  25.  
  26.     for( ; *s; s++ )
  27.         if( *s == c )
  28.             return (char *)s;
  29.  
  30.     if( (char)0 == c ) return (char *)s;
  31.  
  32.     return (char *)0;
  33. }
  34.  
  35. PR_IMPLEMENT(char *)
  36. PL_strrchr(const char *s, char c)
  37. {
  38.     const char *p;
  39.  
  40.     if( (const char *)0 == s ) return (char *)0;
  41.  
  42.     for( p = s; *p; p++ )
  43.         ;
  44.  
  45.     for( ; p >= s; p-- )
  46.         if( *p == c )
  47.             return (char *)p;
  48.  
  49.     return (char *)0;
  50. }
  51.  
  52. PR_IMPLEMENT(char *)
  53. PL_strnchr(const char *s, char c, PRUint32 n)
  54. {
  55.     if( (const char *)0 == s ) return (char *)0;
  56.  
  57.     for( ; *s && n; s++, n-- )
  58.         if( *s == c )
  59.             return (char *)s;
  60.  
  61.     if( ((char)0 == c) && ((char)0 == *s) && (n > 0)) return (char *)s;
  62.  
  63.     return (char *)0;
  64. }
  65.  
  66. PR_IMPLEMENT(char *)
  67. PL_strnrchr(const char *s, char c, PRUint32 n)
  68. {
  69.     const char *p;
  70.  
  71.     if( (const char *)0 == s ) return (char *)0;
  72.  
  73.     for( p = s; *p && n; p++, n-- )
  74.         ;
  75.  
  76.     if( ((char)0 == c) && ((char)0 == *p) && (n > 0) ) return (char *)p;
  77.  
  78.     for( p--; p >= s; p-- )
  79.         if( *p == c )
  80.             return (char *)p;
  81.  
  82.     return (char *)0;
  83. }
  84.