Back to index

lightning-sunbird  0.9+nobinonly
strccmp.c
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "plstr.h"
00039 
00040 static const unsigned char uc[] =
00041 {
00042     '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
00043     '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
00044     '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
00045     '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
00046     ' ',    '!',    '"',    '#',    '$',    '%',    '&',    '\'',
00047     '(',    ')',    '*',    '+',    ',',    '-',    '.',    '/',
00048     '0',    '1',    '2',    '3',    '4',    '5',    '6',    '7',
00049     '8',    '9',    ':',    ';',    '<',    '=',    '>',    '?',
00050     '@',    'A',    'B',    'C',    'D',    'E',    'F',    'G',
00051     'H',    'I',    'J',    'K',    'L',    'M',    'N',    'O',
00052     'P',    'Q',    'R',    'S',    'T',    'U',    'V',    'W',
00053     'X',    'Y',    'Z',    '[',    '\\',   ']',    '^',    '_',
00054     '`',    'A',    'B',    'C',    'D',    'E',    'F',    'G',
00055     'H',    'I',    'J',    'K',    'L',    'M',    'N',    'O',
00056     'P',    'Q',    'R',    'S',    'T',    'U',    'V',    'W',
00057     'X',    'Y',    'Z',    '{',    '|',    '}',    '~',    '\177',
00058     0200,   0201,   0202,   0203,   0204,   0205,   0206,   0207,
00059     0210,   0211,   0212,   0213,   0214,   0215,   0216,   0217,
00060     0220,   0221,   0222,   0223,   0224,   0225,   0226,   0227,
00061     0230,   0231,   0232,   0233,   0234,   0235,   0236,   0237,
00062     0240,   0241,   0242,   0243,   0244,   0245,   0246,   0247,
00063     0250,   0251,   0252,   0253,   0254,   0255,   0256,   0257,
00064     0260,   0261,   0262,   0263,   0264,   0265,   0266,   0267,
00065     0270,   0271,   0272,   0273,   0274,   0275,   0276,   0277,
00066     0300,   0301,   0302,   0303,   0304,   0305,   0306,   0307,
00067     0310,   0311,   0312,   0313,   0314,   0315,   0316,   0317,
00068     0320,   0321,   0322,   0323,   0324,   0325,   0326,   0327,
00069     0330,   0331,   0332,   0333,   0334,   0335,   0336,   0337,
00070     0340,   0341,   0342,   0343,   0344,   0345,   0346,   0347,
00071     0350,   0351,   0352,   0353,   0354,   0355,   0356,   0357,
00072     0360,   0361,   0362,   0363,   0364,   0365,   0366,   0367,
00073     0370,   0371,   0372,   0373,   0374,   0375,   0376,   0377
00074 };
00075 
00076 PR_IMPLEMENT(PRIntn)
00077 PL_strcasecmp(const char *a, const char *b)
00078 {
00079     const unsigned char *ua = (const unsigned char *)a;
00080     const unsigned char *ub = (const unsigned char *)b;
00081 
00082     if( ((const char *)0 == a) || (const char *)0 == b ) 
00083         return (PRIntn)(a-b);
00084 
00085     while( (uc[*ua] == uc[*ub]) && ('\0' != *a) )
00086     {
00087         a++;
00088         ua++;
00089         ub++;
00090     }
00091 
00092     return (PRIntn)(uc[*ua] - uc[*ub]);
00093 }
00094 
00095 PR_IMPLEMENT(PRIntn)
00096 PL_strncasecmp(const char *a, const char *b, PRUint32 max)
00097 {
00098     const unsigned char *ua = (const unsigned char *)a;
00099     const unsigned char *ub = (const unsigned char *)b;
00100 
00101     if( ((const char *)0 == a) || (const char *)0 == b ) 
00102         return (PRIntn)(a-b);
00103 
00104     while( max && (uc[*ua] == uc[*ub]) && ('\0' != *a) )
00105     {
00106         a++;
00107         ua++;
00108         ub++;
00109         max--;
00110     }
00111 
00112     if( 0 == max ) return (PRIntn)0;
00113 
00114     return (PRIntn)(uc[*ua] - uc[*ub]);
00115 }