lcUtil.c revision 61b2299d
1/* $Xorg: lcUtil.c,v 1.3 2000/08/17 19:45:20 cpqbld Exp $ */ 2/* 3 * Copyright 1992, 1993 by TOSHIBA Corp. 4 * 5 * Permission to use, copy, modify, and distribute this software and its 6 * documentation for any purpose and without fee is hereby granted, provided 7 * that the above copyright notice appear in all copies and that both that 8 * copyright notice and this permission notice appear in supporting 9 * documentation, and that the name of TOSHIBA not be used in advertising 10 * or publicity pertaining to distribution of the software without specific, 11 * written prior permission. TOSHIBA make no representations about the 12 * suitability of this software for any purpose. It is provided "as is" 13 * without express or implied warranty. 14 * 15 * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 16 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 17 * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 18 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 19 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 20 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 21 * SOFTWARE. 22 * 23 * Author: Katsuhisa Yano TOSHIBA Corp. 24 * mopi@osa.ilab.toshiba.co.jp 25 * Bug fixes: Bruno Haible XFree86 Inc. 26 */ 27/* $XFree86: xc/lib/X11/lcUtil.c,v 1.3 2000/11/29 17:40:24 dawes Exp $ */ 28 29#ifdef HAVE_CONFIG_H 30#include <config.h> 31#endif 32#include <X11/Xlib.h> 33#include "XlcPublic.h" 34 35/* Don't use <ctype.h> here because it is locale dependent. */ 36 37#define set_toupper(ch) \ 38 if (ch >= 'a' && ch <= 'z') \ 39 ch = ch - 'a' + 'A'; 40 41/* Compares two ISO 8859-1 strings, ignoring case of ASCII letters. 42 Like strcasecmp in an ASCII locale. */ 43int 44_XlcCompareISOLatin1( 45 const char *str1, 46 const char *str2) 47{ 48 unsigned char ch1, ch2; 49 50 for ( ; ; str1++, str2++) { 51 ch1 = *str1; 52 ch2 = *str2; 53 if (ch1 == '\0' || ch2 == '\0') 54 break; 55 set_toupper(ch1); 56 set_toupper(ch2); 57 if (ch1 != ch2) 58 break; 59 } 60 61 return ch1 - ch2; 62} 63 64/* Compares two ISO 8859-1 strings, at most len bytes of each, ignoring 65 case of ASCII letters. Like strncasecmp in an ASCII locale. */ 66int 67_XlcNCompareISOLatin1( 68 const char *str1, 69 const char *str2, 70 int len) 71{ 72 unsigned char ch1, ch2; 73 74 for ( ; ; str1++, str2++, len--) { 75 if (len == 0) 76 return 0; 77 ch1 = *str1; 78 ch2 = *str2; 79 if (ch1 == '\0' || ch2 == '\0') 80 break; 81 set_toupper(ch1); 82 set_toupper(ch2); 83 if (ch1 != ch2) 84 break; 85 } 86 87 return ch1 - ch2; 88} 89