Moved matchstr to global util
[yaz-moved-to-github.git] / util / yaz-util.c
diff --git a/util/yaz-util.c b/util/yaz-util.c
new file mode 100644 (file)
index 0000000..87fb1d5
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 1995, Index Data.
+ * See the file LICENSE for details.
+ * Sebastian Hammer, Adam Dickmeiss
+ *
+ * $Log: yaz-util.c,v $
+ * Revision 1.1  1996-02-20 16:33:06  quinn
+ * Moved matchstr to global util
+ *
+ * Revision 1.1  1995/11/01  11:56:08  quinn
+ * Added Retrieval (data management) functions en masse.
+ *
+ *
+ */
+
+#include <ctype.h>
+
+/*
+ * Match strings, independently of case and occurences of '-'.
+ * fairly inefficient - will be replaced with an indexing scheme for
+ * the various subsystems if we get a bottleneck here.
+ */
+
+int yaz_matchstr(char *s1, char *s2)
+{
+    while (*s1 && *s2)
+    {
+       char c1, c2;
+
+       if (*s1 == '-')
+           s1++;
+       if (*s2 == '-')
+           s2++;
+       if (!*s1 || !*s2)
+           break;
+       c1 = *s1;
+       c2 = *s2;
+       if (isupper(c1))
+           c1 = tolower(c1);
+       if (isupper(c2))
+           c2 = tolower(c2);
+       if (c1 != c2)
+           break;
+       s1++;
+       s2++;
+    }
+    return *s1 || *s2;
+}