lcUtil.c revision 61b2299d
11ab64890Smrg/* $Xorg: lcUtil.c,v 1.3 2000/08/17 19:45:20 cpqbld Exp $ */
21ab64890Smrg/*
31ab64890Smrg * Copyright 1992, 1993 by TOSHIBA Corp.
41ab64890Smrg *
51ab64890Smrg * Permission to use, copy, modify, and distribute this software and its
61ab64890Smrg * documentation for any purpose and without fee is hereby granted, provided
71ab64890Smrg * that the above copyright notice appear in all copies and that both that
81ab64890Smrg * copyright notice and this permission notice appear in supporting
91ab64890Smrg * documentation, and that the name of TOSHIBA not be used in advertising
101ab64890Smrg * or publicity pertaining to distribution of the software without specific,
111ab64890Smrg * written prior permission. TOSHIBA make no representations about the
121ab64890Smrg * suitability of this software for any purpose.  It is provided "as is"
131ab64890Smrg * without express or implied warranty.
141ab64890Smrg *
151ab64890Smrg * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
161ab64890Smrg * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
171ab64890Smrg * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
181ab64890Smrg * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
191ab64890Smrg * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
201ab64890Smrg * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
211ab64890Smrg * SOFTWARE.
221ab64890Smrg *
231ab64890Smrg * Author: Katsuhisa Yano	TOSHIBA Corp.
241ab64890Smrg *			   	mopi@osa.ilab.toshiba.co.jp
251ab64890Smrg * Bug fixes: Bruno Haible	XFree86 Inc.
261ab64890Smrg */
271ab64890Smrg/* $XFree86: xc/lib/X11/lcUtil.c,v 1.3 2000/11/29 17:40:24 dawes Exp $ */
281ab64890Smrg
291ab64890Smrg#ifdef HAVE_CONFIG_H
301ab64890Smrg#include <config.h>
311ab64890Smrg#endif
321ab64890Smrg#include <X11/Xlib.h>
331ab64890Smrg#include "XlcPublic.h"
341ab64890Smrg
351ab64890Smrg/* Don't use <ctype.h> here because it is locale dependent. */
361ab64890Smrg
371ab64890Smrg#define set_toupper(ch) \
381ab64890Smrg  if (ch >= 'a' && ch <= 'z') \
391ab64890Smrg    ch = ch - 'a' + 'A';
401ab64890Smrg
411ab64890Smrg/* Compares two ISO 8859-1 strings, ignoring case of ASCII letters.
421ab64890Smrg   Like strcasecmp in an ASCII locale. */
4361b2299dSmrgint
441ab64890Smrg_XlcCompareISOLatin1(
451ab64890Smrg    const char *str1,
461ab64890Smrg    const char *str2)
471ab64890Smrg{
481ab64890Smrg    unsigned char ch1, ch2;
491ab64890Smrg
501ab64890Smrg    for ( ; ; str1++, str2++) {
511ab64890Smrg	ch1 = *str1;
521ab64890Smrg	ch2 = *str2;
531ab64890Smrg	if (ch1 == '\0' || ch2 == '\0')
541ab64890Smrg	    break;
551ab64890Smrg	set_toupper(ch1);
561ab64890Smrg	set_toupper(ch2);
571ab64890Smrg	if (ch1 != ch2)
581ab64890Smrg	    break;
591ab64890Smrg    }
601ab64890Smrg
611ab64890Smrg    return ch1 - ch2;
621ab64890Smrg}
631ab64890Smrg
641ab64890Smrg/* Compares two ISO 8859-1 strings, at most len bytes of each, ignoring
651ab64890Smrg   case of ASCII letters. Like strncasecmp in an ASCII locale. */
6661b2299dSmrgint
671ab64890Smrg_XlcNCompareISOLatin1(
681ab64890Smrg    const char *str1,
691ab64890Smrg    const char *str2,
701ab64890Smrg    int len)
711ab64890Smrg{
721ab64890Smrg    unsigned char ch1, ch2;
731ab64890Smrg
741ab64890Smrg    for ( ; ; str1++, str2++, len--) {
751ab64890Smrg	if (len == 0)
761ab64890Smrg	    return 0;
771ab64890Smrg	ch1 = *str1;
781ab64890Smrg	ch2 = *str2;
791ab64890Smrg	if (ch1 == '\0' || ch2 == '\0')
801ab64890Smrg	    break;
811ab64890Smrg	set_toupper(ch1);
821ab64890Smrg	set_toupper(ch2);
831ab64890Smrg	if (ch1 != ch2)
841ab64890Smrg	    break;
851ab64890Smrg    }
861ab64890Smrg
871ab64890Smrg    return ch1 - ch2;
881ab64890Smrg}
89