X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fmatchstr.c;h=686991867b7475a2e1bde16a46cd95d7b4db1f5a;hp=e2a1da3579ad5552623cc2dbc0d45b3bccf3b3cb;hb=5a0398df33ef2f0ed66ef4703c13b3edae754bae;hpb=8e9d2cec97def1cd8b89b1fe427f1a232661ec6f diff --git a/src/matchstr.c b/src/matchstr.c index e2a1da3..6869918 100644 --- a/src/matchstr.c +++ b/src/matchstr.c @@ -1,11 +1,11 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2008 Index Data + * Copyright (C) Index Data * See the file LICENSE for details. */ /** * \file matchstr.c - * \brief Implements loose string matching + * \brief a couple of string utilities */ #if HAVE_CONFIG_H @@ -14,9 +14,30 @@ #include #include -#include #include -#include +#include +#include + +int yaz_strcasecmp(const char *s1, const char *s2) +{ + return yaz_strncasecmp(s1, s2, strlen(s1) + 1); +} + +int yaz_strncasecmp(const char *s1, const char *s2, size_t n) +{ + while (n--) + { + unsigned char c1 = *s1++; + unsigned char c2 = *s2++; + if (yaz_isupper(c1)) + c1 = yaz_tolower(c1); + if (yaz_isupper(c2)) + c2 = yaz_tolower(c2); + if (c1 != c2) + return c1 - c2; + } + return 0; +} int yaz_matchstr(const char *s1, const char *s2) { @@ -35,10 +56,10 @@ int yaz_matchstr(const char *s1, const char *s2) break; if (c2 != '.') { - if (isupper(c1)) - c1 = tolower(c1); - if (isupper(c2)) - c2 = tolower(c2); + if (yaz_isupper(c1)) + c1 = yaz_tolower(c1); + if (yaz_isupper(c2)) + c2 = yaz_tolower(c2); if (c1 != c2) break; } @@ -71,9 +92,24 @@ int yaz_memcmp(const void *a, const void *b, size_t len_a, size_t len_b) return len_a - len_b; } +int yaz_strcmp_null(const char *v1, const char *v2) +{ + if (v1) + { + if (v2) + return strcmp(v1, v2); + else + return 1; + } + else if (v2) + return -1; + return 0; +} + /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab