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

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       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             : static const unsigned char uc[] =
      10             : {
      11             :     '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
      12             :     '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
      13             :     '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
      14             :     '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
      15             :     ' ',    '!',    '"',    '#',    '$',    '%',    '&',    '\'',
      16             :     '(',    ')',    '*',    '+',    ',',    '-',    '.',    '/',
      17             :     '0',    '1',    '2',    '3',    '4',    '5',    '6',    '7',
      18             :     '8',    '9',    ':',    ';',    '<',    '=',    '>',    '?',
      19             :     '@',    'A',    'B',    'C',    'D',    'E',    'F',    'G',
      20             :     'H',    'I',    'J',    'K',    'L',    'M',    'N',    'O',
      21             :     'P',    'Q',    'R',    'S',    'T',    'U',    'V',    'W',
      22             :     'X',    'Y',    'Z',    '[',    '\\',   ']',    '^',    '_',
      23             :     '`',    'A',    'B',    'C',    'D',    'E',    'F',    'G',
      24             :     'H',    'I',    'J',    'K',    'L',    'M',    'N',    'O',
      25             :     'P',    'Q',    'R',    'S',    'T',    'U',    'V',    'W',
      26             :     'X',    'Y',    'Z',    '{',    '|',    '}',    '~',    '\177',
      27             :     0200,   0201,   0202,   0203,   0204,   0205,   0206,   0207,
      28             :     0210,   0211,   0212,   0213,   0214,   0215,   0216,   0217,
      29             :     0220,   0221,   0222,   0223,   0224,   0225,   0226,   0227,
      30             :     0230,   0231,   0232,   0233,   0234,   0235,   0236,   0237,
      31             :     0240,   0241,   0242,   0243,   0244,   0245,   0246,   0247,
      32             :     0250,   0251,   0252,   0253,   0254,   0255,   0256,   0257,
      33             :     0260,   0261,   0262,   0263,   0264,   0265,   0266,   0267,
      34             :     0270,   0271,   0272,   0273,   0274,   0275,   0276,   0277,
      35             :     0300,   0301,   0302,   0303,   0304,   0305,   0306,   0307,
      36             :     0310,   0311,   0312,   0313,   0314,   0315,   0316,   0317,
      37             :     0320,   0321,   0322,   0323,   0324,   0325,   0326,   0327,
      38             :     0330,   0331,   0332,   0333,   0334,   0335,   0336,   0337,
      39             :     0340,   0341,   0342,   0343,   0344,   0345,   0346,   0347,
      40             :     0350,   0351,   0352,   0353,   0354,   0355,   0356,   0357,
      41             :     0360,   0361,   0362,   0363,   0364,   0365,   0366,   0367,
      42             :     0370,   0371,   0372,   0373,   0374,   0375,   0376,   0377
      43             : };
      44             : 
      45             : PR_IMPLEMENT(PRIntn)
      46             : PL_strcasecmp(const char *a, const char *b)
      47             : {
      48       31326 :     const unsigned char *ua = (const unsigned char *)a;
      49       31326 :     const unsigned char *ub = (const unsigned char *)b;
      50             : 
      51       31326 :     if( (const char *)0 == a )
      52           0 :         return ((const char *)0 == b) ? 0 : -1;
      53       31326 :     if( (const char *)0 == b )
      54           0 :         return 1;
      55             : 
      56      120435 :     while( (uc[*ua] == uc[*ub]) && ('\0' != *a) )
      57             :     {
      58       57783 :         a++;
      59       57783 :         ua++;
      60       57783 :         ub++;
      61             :     }
      62             : 
      63       31326 :     return (PRIntn)(uc[*ua] - uc[*ub]);
      64             : }
      65             : 
      66             : PR_IMPLEMENT(PRIntn)
      67             : PL_strncasecmp(const char *a, const char *b, PRUint32 max)
      68             : {
      69       14013 :     const unsigned char *ua = (const unsigned char *)a;
      70       14013 :     const unsigned char *ub = (const unsigned char *)b;
      71             : 
      72       14013 :     if( (const char *)0 == a )
      73           0 :         return ((const char *)0 == b) ? 0 : -1;
      74       14013 :     if( (const char *)0 == b )
      75           0 :         return 1;
      76             : 
      77       31521 :     while( max && (uc[*ua] == uc[*ub]) && ('\0' != *a) )
      78             :     {
      79        3495 :         a++;
      80        3495 :         ua++;
      81        3495 :         ub++;
      82        3495 :         max--;
      83             :     }
      84             : 
      85       14013 :     if( 0 == max ) return (PRIntn)0;
      86             : 
      87       12573 :     return (PRIntn)(uc[*ua] - uc[*ub]);
      88             : }
      89             : 
      90             : PR_IMPLEMENT(char *)
      91             : PL_strcasestr(const char *big, const char *little)
      92             : {
      93             :     PRUint32 ll;
      94             : 
      95          34 :     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
      96          34 :     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
      97             : 
      98          33 :     ll = strlen(little);
      99             : 
     100         621 :     for( ; *big; big++ )
     101             :         /* obvious improvement available here */
     102         607 :             if( 0 == PL_strncasecmp(big, little, ll) )
     103          19 :                 return (char *)big;
     104             : 
     105          14 :     return (char *)0;
     106             : }
     107             : 
     108             : PR_IMPLEMENT(char *)
     109             : PL_strcaserstr(const char *big, const char *little)
     110             : {
     111             :     const char *p;
     112             :     PRUint32 bl, ll;
     113             : 
     114           0 :     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
     115           0 :     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
     116             : 
     117           0 :     bl = strlen(big);
     118           0 :     ll = strlen(little);
     119           0 :     if( bl < ll ) return (char *)0;
     120           0 :     p = &big[ bl - ll ];
     121             : 
     122           0 :     for( ; p >= big; p-- )
     123             :         /* obvious improvement available here */
     124           0 :             if( 0 == PL_strncasecmp(p, little, ll) )
     125           0 :                 return (char *)p;
     126             : 
     127           0 :     return (char *)0;
     128             : }
     129             : 
     130             : PR_IMPLEMENT(char *)
     131             : PL_strncasestr(const char *big, const char *little, PRUint32 max)
     132             : {
     133             :     PRUint32 ll;
     134             : 
     135        1727 :     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
     136        1727 :     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
     137             : 
     138        1727 :     ll = strlen(little);
     139        1727 :     if( ll > max ) return (char *)0;
     140         816 :     max -= ll;
     141         816 :     max++;
     142             : 
     143        5223 :     for( ; max && *big; big++, max-- )
     144             :         /* obvious improvement available here */
     145        4407 :             if( 0 == PL_strncasecmp(big, little, ll) )
     146           0 :                 return (char *)big;
     147             : 
     148         816 :     return (char *)0;
     149             : }
     150             : 
     151             : PR_IMPLEMENT(char *)
     152             : PL_strncaserstr(const char *big, const char *little, PRUint32 max)
     153             : {
     154             :     const char *p;
     155             :     PRUint32 ll;
     156             : 
     157           0 :     if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
     158           0 :     if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
     159             : 
     160           0 :     ll = strlen(little);
     161             : 
     162           0 :     for( p = big; max && *p; p++, max-- )
     163             :         ;
     164             : 
     165           0 :     p -= ll;
     166           0 :     if( p < big ) return (char *)0;
     167             : 
     168           0 :     for( ; p >= big; p-- )
     169             :         /* obvious improvement available here */
     170           0 :             if( 0 == PL_strncasecmp(p, little, ll) )
     171           0 :                 return (char *)p;
     172             : 
     173           0 :     return (char *)0;
     174             : }

Generated by: LCOV version 1.13