X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fmatchstr.c;h=101e777b75b81327469a778684799878ef760e7b;hp=2ec92d81f926396c83d1846119308a73c744abae;hb=1346b30779b120691e4145a3578716f77300951e;hpb=c6e47cbbff56f39f6d81b079ebaeac41d793d4d9 diff --git a/src/matchstr.c b/src/matchstr.c index 2ec92d8..101e777 100644 --- a/src/matchstr.c +++ b/src/matchstr.c @@ -1,52 +1,49 @@ -/* - * Copyright (c) 1995-2003, Index Data. +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2013 Index Data * See the file LICENSE for details. - * Sebastian Hammer, Adam Dickmeiss - * - * $Id: matchstr.c,v 1.1 2003-10-27 12:21:31 adam Exp $ */ + +/** + * \file matchstr.c + * \brief a couple of string utilities + */ + #if HAVE_CONFIG_H #include #endif #include #include -#include #include -#include - -/* - * 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. - */ +#include +#include int yaz_matchstr(const char *s1, const char *s2) { while (*s1 && *s2) { - char c1 = *s1; - char c2 = *s2; + unsigned char c1 = *s1; + unsigned char c2 = *s2; if (c2 == '?') return 0; - if (c1 == '-') - c1 = *++s1; - if (c2 == '-') - c2 = *++s2; - if (!c1 || !c2) - break; + if (c1 == '-') + c1 = *++s1; + if (c2 == '-') + c2 = *++s2; + if (!c1 || !c2) + break; if (c2 != '.') { - if (isupper(c1)) - c1 = tolower(c1); - if (isupper(c2)) - c2 = tolower(c2); - if (c1 != c2) - break; + if (yaz_isupper(c1)) + c1 = yaz_tolower(c1); + if (yaz_isupper(c2)) + c2 = yaz_tolower(c2); + if (c1 != c2) + break; } - s1++; - s2++; + s1++; + s2++; } return *s1 || *s2; } @@ -65,14 +62,21 @@ int yaz_strcmp_del(const char *a, const char *b, const char *b_del) return *a - *b; } -#ifdef __GNUC__ -#ifdef __CHECKER__ -void __assert_fail (const char *assertion, const char *file, - unsigned int line, const char *function) +int yaz_memcmp(const void *a, const void *b, size_t len_a, size_t len_b) { - fprintf (stderr, "%s in file %s line %d func %s\n", - assertion, file, line, function); - abort (); + size_t m_len = len_a < len_b ? len_a : len_b; + int r = memcmp(a, b, m_len); + if (r) + return r; + return len_a - len_b; } -#endif -#endif + +/* + * Local variables: + * c-basic-offset: 4 + * c-file-style: "Stroustrup" + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +