a5b73d8bc6ee9096c5d42e5f34494ab734610c44
[yaz-moved-to-github.git] / src / cclstr.c
1 /*
2  * Copyright (C) 1995-2008, Index Data ApS
3  * See the file LICENSE for details.
4  *
5  * $Id: cclstr.c,v 1.4 2008-01-09 21:32:28 adam Exp $
6  */
7 /** 
8  * \file cclstr.c
9  * \brief Implements CCL string compare utilities
10  */
11 #include <ctype.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14
15 #include <yaz/ccl.h>
16
17 static int ccli_toupper (int c)
18 {
19     return toupper (c);
20 }
21
22 int (*ccl_toupper)(int c) = NULL;
23
24 int ccl_stricmp (const char *s1, const char *s2)
25 {
26     if (!ccl_toupper)
27         ccl_toupper = ccli_toupper;
28     while (*s1 && *s2)
29     {
30         int c1, c2;
31         c1 = (*ccl_toupper)(*s1);
32         c2 = (*ccl_toupper)(*s2);
33         if (c1 != c2)
34             return c1 - c2;
35         s1++;
36         s2++;
37     }
38     return (*ccl_toupper)(*s1) - (*ccl_toupper)(*s2);
39 }
40
41 int ccl_memicmp (const char *s1, const char *s2, size_t n)
42 {
43     if (!ccl_toupper)
44         ccl_toupper = ccli_toupper;
45     while (1)
46     {
47         int c1, c2;
48
49         c1 = (*ccl_toupper)(*s1);
50         c2 = (*ccl_toupper)(*s2);
51         if (n <= 1 || c1 != c2)
52             return c1 - c2;
53         s1++;
54         s2++;
55         --n;
56     }
57 }
58
59 /*
60  * Local variables:
61  * c-basic-offset: 4
62  * indent-tabs-mode: nil
63  * End:
64  * vim: shiftwidth=4 tabstop=8 expandtab
65  */
66