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

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

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

Generated by: LCOV version 1.7