Right hande side operand of yaz_matchstr may include a ? in
[yaz-moved-to-github.git] / util / yaz-util.c
1 /*
2  * Copyright (c) 1995-1997, Index Data.
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: yaz-util.c,v $
7  * Revision 1.6  1997-09-04 07:54:34  adam
8  * Right hande side operand of yaz_matchstr may include a ? in
9  * which case it returns "match ok".
10  *
11  * Revision 1.5  1997/07/21 12:48:11  adam
12  * Removed windows DLL stubs.
13  *
14  * Revision 1.4  1997/05/01 15:07:55  adam
15  * Added DLL entry point routines.
16  *
17  * Revision 1.3  1996/10/29 13:36:28  adam
18  * Added header.
19  *
20  * Revision 1.2  1996/02/20 17:58:42  adam
21  * Added const to yaz_matchstr.
22  *
23  * Revision 1.1  1996/02/20  16:33:06  quinn
24  * Moved matchstr to global util
25  *
26  * Revision 1.1  1995/11/01  11:56:08  quinn
27  * Added Retrieval (data management) functions en masse.
28  *
29  *
30  */
31
32 #include <ctype.h>
33 #include <yaz-util.h>
34 /*
35  * Match strings, independently of case and occurences of '-'.
36  * fairly inefficient - will be replaced with an indexing scheme for
37  * the various subsystems if we get a bottleneck here.
38  */
39
40 int yaz_matchstr(const char *s1, const char *s2)
41 {
42     while (*s1 && *s2)
43     {
44         char c1, c2;
45
46         if (*s2 == '?')
47             return 0;
48         if (*s1 == '-')
49             s1++;
50         if (*s2 == '-')
51             s2++;
52         if (!*s1 || !*s2)
53             break;
54         c1 = *s1;
55         c2 = *s2;
56         if (isupper(c1))
57             c1 = tolower(c1);
58         if (isupper(c2))
59             c2 = tolower(c2);
60         if (c1 != c2)
61             break;
62         s1++;
63         s2++;
64     }
65     return *s1 || *s2;
66 }