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