home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / lib / libc / src / strccmp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.8 KB  |  81 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "plstr.h"
  20.  
  21. static const unsigned char uc[] =
  22. {
  23.     '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
  24.     '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
  25.     '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
  26.     '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
  27.     ' ',    '!',    '"',    '#',    '$',    '%',    '&',    '\'',
  28.     '(',    ')',    '*',    '+',    ',',    '-',    '.',    '/',
  29.     '0',    '1',    '2',    '3',    '4',    '5',    '6',    '7',
  30.     '8',    '9',    ':',    ';',    '<',    '=',    '>',    '?',
  31.     '@',    'A',    'B',    'C',    'D',    'E',    'F',    'G',
  32.     'H',    'I',    'J',    'K',    'L',    'M',    'N',    'O',
  33.     'P',    'Q',    'R',    'S',    'T',    'U',    'V',    'W',
  34.     'X',    'Y',    'Z',    '[',    '\\',   ']',    '^',    '_',
  35.     '`',    'A',    'B',    'C',    'D',    'E',    'F',    'G',
  36.     'H',    'I',    'J',    'K',    'L',    'M',    'N',    'O',
  37.     'P',    'Q',    'R',    'S',    'T',    'U',    'V',    'W',
  38.     'X',    'Y',    'Z',    '{',    '|',    '}',    '~',    '\177'
  39. };
  40.  
  41. PR_IMPLEMENT(PRIntn)
  42. PL_strcasecmp(const char *a, const char *b)
  43. {
  44.     const unsigned char *ua = (const unsigned char *)a;
  45.     const unsigned char *ub = (const unsigned char *)b;
  46.  
  47.     if( ((const char *)0 == a) || (const char *)0 == b ) 
  48.         return (PRIntn)(a-b);
  49.  
  50.     while( (uc[*ua] == uc[*ub]) && ('\0' != *a) )
  51.     {
  52.         a++;
  53.         ua++;
  54.         ub++;
  55.     }
  56.  
  57.     return (PRIntn)(uc[*ua] - uc[*ub]);
  58. }
  59.  
  60. PR_IMPLEMENT(PRIntn)
  61. PL_strncasecmp(const char *a, const char *b, PRUint32 max)
  62. {
  63.     const unsigned char *ua = (const unsigned char *)a;
  64.     const unsigned char *ub = (const unsigned char *)b;
  65.  
  66.     if( ((const char *)0 == a) || (const char *)0 == b ) 
  67.         return (PRIntn)(a-b);
  68.  
  69.     while( max && (uc[*ua] == uc[*ub]) && ('\0' != *a) )
  70.     {
  71.         a++;
  72.         ua++;
  73.         ub++;
  74.         max--;
  75.     }
  76.  
  77.     if( 0 == max ) return (PRIntn)0;
  78.  
  79.     return (PRIntn)(uc[*ua] - uc[*ub]);
  80. }
  81.