Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

strcasecmp.c

00001 /*
00002  * Copyright (c) 1987, 1993
00003  *      The Regents of the University of California.  All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. All advertising materials mentioning features or use of this software
00014  *    must display the following acknowledgement:
00015  *      This product includes software developed by the University of
00016  *      California, Berkeley and its contributors.
00017  * 4. Neither the name of the University nor the names of its contributors
00018  *    may be used to endorse or promote products derived from this software
00019  *    without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00022  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00024  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00025  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00026  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00027  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00028  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00030  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00031  * SUCH DAMAGE.
00032  *
00033  * $Id: strcasecmp.c,v 12.0 2004/11/17 03:43:15 bostic Exp $
00034  */
00035 
00036 #include "db_config.h"
00037 
00038 #ifndef NO_SYSTEM_INCLUDES
00039 #include <string.h>
00040 #endif
00041 
00042 /*
00043  * This array is designed for mapping upper and lower case letter
00044  * together for a case independent comparison.  The mappings are
00045  * based upon ascii character sequences.
00046  */
00047 static const unsigned char charmap[] = {
00048         '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
00049         '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
00050         '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
00051         '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
00052         '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
00053         '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
00054         '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
00055         '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
00056         '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
00057         '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
00058         '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
00059         '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
00060         '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
00061         '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
00062         '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
00063         '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
00064         '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
00065         '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
00066         '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
00067         '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
00068         '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
00069         '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
00070         '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
00071         '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
00072         '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
00073         '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
00074         '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
00075         '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
00076         '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
00077         '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
00078         '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
00079         '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377'
00080 };
00081 
00082 /*
00083  * strcasecmp --
00084  *      Do strcmp(3) in a case-insensitive manner.
00085  *
00086  * PUBLIC: #ifndef HAVE_STRCASECMP
00087  * PUBLIC: int strcasecmp __P((const char *, const char *));
00088  * PUBLIC: #endif
00089  */
00090 int
00091 strcasecmp(s1, s2)
00092         const char *s1, *s2;
00093 {
00094         register const unsigned char *cm = charmap,
00095                         *us1 = (const unsigned char *)s1,
00096                         *us2 = (const unsigned char *)s2;
00097 
00098         while (cm[*us1] == cm[*us2++])
00099                 if (*us1++ == '\0')
00100                         return (0);
00101         return (cm[*us1] - cm[*--us2]);
00102 }
00103 
00104 /*
00105  * strncasecmp --
00106  *      Do strncmp(3) in a case-insensitive manner.
00107  *
00108  * PUBLIC: #ifndef HAVE_STRCASECMP
00109  * PUBLIC: int strncasecmp __P((const char *, const char *, size_t));
00110  * PUBLIC: #endif
00111  */
00112 int
00113 strncasecmp(s1, s2, n)
00114         const char *s1, *s2;
00115         register size_t n;
00116 {
00117         if (n != 0) {
00118                 register const unsigned char *cm = charmap,
00119                                 *us1 = (const unsigned char *)s1,
00120                                 *us2 = (const unsigned char *)s2;
00121 
00122                 do {
00123                         if (cm[*us1] != cm[*us2++])
00124                                 return (cm[*us1] - cm[*--us2]);
00125                         if (*us1++ == '\0')
00126                                 break;
00127                 } while (--n != 0);
00128         }
00129         return (0);
00130 }

Generated on Sun Dec 25 12:14:17 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2