LCOV - app.info - nsprpub/lib/libc/src/strstr.c

LCOV - code coverage report
| Current view: | directory - nsprpub/lib/libc/src - strstr.c (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 40 | 0 | 0.0 %
| Date: | 2012-04-07 | Functions: | 4 | 0 | 0.0 %

           1                 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
           2                 : /* ***** BEGIN LICENSE BLOCK *****
           3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
           4                 :  *
           5                 :  * The contents of this file are subject to the Mozilla Public License Version
           6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
           7                 :  * the License. You may obtain a copy of the License at
           8                 :  * http://www.mozilla.org/MPL/
           9                 :  *
          10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
          11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
          12                 :  * for the specific language governing rights and limitations under the
          13                 :  * License.
          14                 :  *
          15                 :  * The Original Code is the Netscape Portable Runtime (NSPR).
          16                 :  *
          17                 :  * The Initial Developer of the Original Code is
          18                 :  * Netscape Communications Corporation.
          19                 :  * Portions created by the Initial Developer are Copyright (C) 1998-2000
          20                 :  * the Initial Developer. All Rights Reserved.
          21                 :  *
          22                 :  * Contributor(s):
          23                 :  *
          24                 :  * Alternatively, the contents of this file may be used under the terms of
          25                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
          26                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
          27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
          28                 :  * of those above. If you wish to allow use of your version of this file only
          29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
          30                 :  * use your version of this file under the terms of the MPL, indicate your
          31                 :  * decision by deleting the provisions above and replace them with the notice
          32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
          33                 :  * the provisions above, a recipient may use your version of this file under
          34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
          35                 :  *
          36                 :  * ***** END LICENSE BLOCK ***** */
          37                 :
          38                 : #include "plstr.h"
          39                 : #include <string.h>
          40                 :
          41                 : PR_IMPLEMENT(char *)
          42               0 : PL_strstr(const char *big, const char *little)
          43                 : {
          44               0 :     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
          45               0 :     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
          46                 :
          47               0 :     return strstr(big, little);
          48                 : }
          49                 :
          50                 : PR_IMPLEMENT(char *)
          51               0 : PL_strrstr(const char *big, const char *little)
          52                 : {
          53                 :     const char *p;
          54                 :     size_t ll;
          55                 :     size_t bl;
          56                 :
          57               0 :     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
          58               0 :     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
          59                 :
          60               0 :     ll = strlen(little);
          61               0 :     bl = strlen(big);
          62               0 :     if( bl < ll ) return (char *)0;
          63               0 :     p = &big[ bl - ll ];
          64                 :
          65               0 :     for( ; p >= big; p-- )
          66               0 :         if( *little == *p )
          67               0 :             if( 0 == strncmp(p, little, ll) )
          68               0 :                 return (char *)p;
          69                 :
          70               0 :     return (char *)0;
          71                 : }
          72                 :
          73                 : PR_IMPLEMENT(char *)
          74               0 : PL_strnstr(const char *big, const char *little, PRUint32 max)
          75                 : {
          76                 :     size_t ll;
          77                 :
          78               0 :     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
          79               0 :     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
          80                 :
          81               0 :     ll = strlen(little);
          82               0 :     if( ll > (size_t)max ) return (char *)0;
          83               0 :     max -= (PRUint32)ll;
          84               0 :     max++;
          85                 :
          86               0 :     for( ; max && *big; big++, max-- )
          87               0 :         if( *little == *big )
          88               0 :             if( 0 == strncmp(big, little, ll) )
          89               0 :                 return (char *)big;
          90                 :
          91               0 :     return (char *)0;
          92                 : }
          93                 :
          94                 : PR_IMPLEMENT(char *)
          95               0 : PL_strnrstr(const char *big, const char *little, PRUint32 max)
          96                 : {
          97                 :     const char *p;
          98                 :     size_t ll;
          99                 :
         100               0 :     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
         101               0 :     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
         102                 :
         103               0 :     ll = strlen(little);
         104                 :
         105               0 :     for( p = big; max && *p; p++, max-- )
         106                 :         ;
         107                 :
         108               0 :     p -= ll;
         109               0 :     if( p < big ) return (char *)0;
         110                 :
         111               0 :     for( ; p >= big; p-- )
         112               0 :         if( *little == *p )
         113               0 :             if( 0 == strncmp(p, little, ll) )
         114               0 :                 return (char *)p;
         115                 :
         116               0 :     return (char *)0;
         117                 : }

Generated by: LCOV version 1.7