LCOV - code coverage report
Current view: top level - nsprpub/lib/libc/src - strstr.c (source / functions) Hit Total Coverage
Test: output.info Lines: 3 36 8.3 %
Date: 2017-07-14 16:53:18 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #include "plstr.h"
       7             : #include <string.h>
       8             : 
       9             : PR_IMPLEMENT(char *)
      10             : PL_strstr(const char *big, const char *little)
      11             : {
      12          47 :     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
      13          47 :     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
      14             : 
      15          47 :     return strstr(big, little);
      16             : }
      17             : 
      18             : PR_IMPLEMENT(char *)
      19             : PL_strrstr(const char *big, const char *little)
      20             : {
      21             :     const char *p;
      22             :     size_t ll;
      23             :     size_t bl;
      24             : 
      25           0 :     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
      26           0 :     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
      27             : 
      28           0 :     ll = strlen(little);
      29           0 :     bl = strlen(big);
      30           0 :     if( bl < ll ) return (char *)0;
      31           0 :     p = &big[ bl - ll ];
      32             : 
      33           0 :     for( ; p >= big; p-- )
      34           0 :         if( *little == *p )
      35           0 :             if( 0 == strncmp(p, little, ll) )
      36           0 :                 return (char *)p;
      37             : 
      38           0 :     return (char *)0;
      39             : }
      40             : 
      41             : PR_IMPLEMENT(char *)
      42             : PL_strnstr(const char *big, const char *little, PRUint32 max)
      43             : {
      44             :     size_t ll;
      45             : 
      46           0 :     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
      47           0 :     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
      48             : 
      49           0 :     ll = strlen(little);
      50           0 :     if( ll > (size_t)max ) return (char *)0;
      51           0 :     max -= (PRUint32)ll;
      52           0 :     max++;
      53             : 
      54           0 :     for( ; max && *big; big++, max-- )
      55           0 :         if( *little == *big )
      56           0 :             if( 0 == strncmp(big, little, ll) )
      57           0 :                 return (char *)big;
      58             : 
      59           0 :     return (char *)0;
      60             : }
      61             : 
      62             : PR_IMPLEMENT(char *)
      63             : PL_strnrstr(const char *big, const char *little, PRUint32 max)
      64             : {
      65             :     const char *p;
      66             :     size_t ll;
      67             : 
      68           0 :     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
      69           0 :     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
      70             : 
      71           0 :     ll = strlen(little);
      72             : 
      73           0 :     for( p = big; max && *p; p++, max-- )
      74             :         ;
      75             : 
      76           0 :     p -= ll;
      77           0 :     if( p < big ) return (char *)0;
      78             : 
      79           0 :     for( ; p >= big; p-- )
      80           0 :         if( *little == *p )
      81           0 :             if( 0 == strncmp(p, little, ll) )
      82           0 :                 return (char *)p;
      83             : 
      84           0 :     return (char *)0;
      85             : }

Generated by: LCOV version 1.13