Back to index

lightning-sunbird  0.9+nobinonly
strcstr.c
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "plstr.h"
00039 
00040 PR_IMPLEMENT(char *)
00041 PL_strcasestr(const char *big, const char *little)
00042 {
00043     PRUint32 ll;
00044 
00045     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
00046     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
00047 
00048     ll = PL_strlen(little);
00049 
00050     for( ; *big; big++ )
00051         /* obvious improvement available here */
00052             if( 0 == PL_strncasecmp(big, little, ll) )
00053                 return (char *)big;
00054 
00055     return (char *)0;
00056 }
00057 
00058 PR_IMPLEMENT(char *)
00059 PL_strcaserstr(const char *big, const char *little)
00060 {
00061     const char *p;
00062     PRUint32 ll;
00063 
00064     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
00065     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
00066 
00067     ll = PL_strlen(little);
00068     p = &big[ PL_strlen(big) - ll ];
00069     if( p < big ) return (char *)0;
00070 
00071     for( ; p >= big; p-- )
00072         /* obvious improvement available here */
00073             if( 0 == PL_strncasecmp(p, little, ll) )
00074                 return (char *)p;
00075 
00076     return (char *)0;
00077 }
00078 
00079 PR_IMPLEMENT(char *)
00080 PL_strncasestr(const char *big, const char *little, PRUint32 max)
00081 {
00082     PRUint32 ll;
00083 
00084     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
00085     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
00086 
00087     ll = PL_strlen(little);
00088     if( ll > max ) return (char *)0;
00089     max -= ll;
00090     max++;
00091 
00092     for( ; max && *big; big++, max-- )
00093         /* obvious improvement available here */
00094             if( 0 == PL_strncasecmp(big, little, ll) )
00095                 return (char *)big;
00096 
00097     return (char *)0;
00098 }
00099 
00100 PR_IMPLEMENT(char *)
00101 PL_strncaserstr(const char *big, const char *little, PRUint32 max)
00102 {
00103     const char *p;
00104     PRUint32 ll;
00105 
00106     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
00107     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
00108 
00109     ll = PL_strlen(little);
00110 
00111     for( p = big; max && *p; p++, max-- )
00112         ;
00113 
00114     p -= ll;
00115     if( p < big ) return (char *)0;
00116 
00117     for( ; p >= big; p-- )
00118         /* obvious improvement available here */
00119             if( 0 == PL_strncasecmp(p, little, ll) )
00120                 return (char *)p;
00121 
00122     return (char *)0;
00123 }