index set -> context set
[yaz-moved-to-github.git] / src / matchstr.c
1 /*
2  * Copyright (c) 1995-2003, Index Data.
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Id: matchstr.c,v 1.1 2003-10-27 12:21:31 adam Exp $
7  */
8 #if HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11
12 #include <stdio.h>
13 #include <assert.h>
14 #include <ctype.h>
15 #include <string.h>
16 #include <yaz/yaz-util.h>
17
18 /*
19  * Match strings, independently of case and occurences of '-'.
20  * fairly inefficient - will be replaced with an indexing scheme for
21  * the various subsystems if we get a bottleneck here.
22  */
23
24 int yaz_matchstr(const char *s1, const char *s2)
25 {
26     while (*s1 && *s2)
27     {
28         char c1 = *s1;
29         char c2 = *s2;
30
31         if (c2 == '?')
32             return 0;
33         if (c1 == '-')
34             c1 = *++s1;
35         if (c2 == '-')
36             c2 = *++s2;
37         if (!c1 || !c2)
38             break;
39         if (c2 != '.')
40         {
41             if (isupper(c1))
42                 c1 = tolower(c1);
43             if (isupper(c2))
44                 c2 = tolower(c2);
45             if (c1 != c2)
46                 break;
47         }
48         s1++;
49         s2++;
50     }
51     return *s1 || *s2;
52 }
53
54 int yaz_strcmp_del(const char *a, const char *b, const char *b_del)
55 {
56     while (*a && *b)
57     {
58         if (*a != *b)
59             return *a - *b;
60         a++;
61         b++;
62     }
63     if (b_del && strchr(b_del, *b))
64         return *a;
65     return *a - *b;
66 }
67
68 #ifdef __GNUC__
69 #ifdef __CHECKER__
70 void __assert_fail (const char *assertion, const char *file, 
71                     unsigned int line, const char *function)
72 {
73     fprintf (stderr, "%s in file %s line %d func %s\n",
74              assertion, file, line, function);
75     abort ();
76 }
77 #endif
78 #endif