YAZ 5.35.1
match_glob.c
Go to the documentation of this file.
1/* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
4 */
9#if HAVE_CONFIG_H
10#include <config.h>
11#endif
12
13#include <assert.h>
14#include <stdlib.h>
15#include <string.h>
16#include <ctype.h>
17
18#include <yaz/xmalloc.h>
19#include <yaz/wrbuf.h>
20#include <yaz/match_glob.h>
21
22int yaz_match_glob(const char *glob, const char *text)
23{
24 return yaz_match_glob2(glob, text, 0);
25}
26
27int yaz_match_glob2(const char *glob, const char *text, int case_insensitive)
28{
29 while (1)
30 {
31 if (*glob == '\0')
32 return *text == '\0';
33 if (*glob == '*')
34 {
35 do
36 {
37 if (yaz_match_glob2(glob+1, text, case_insensitive))
38 return 1;
39 }
40 while (*text++);
41 return 0;
42 }
43 if (!*text)
44 return 0;
45 if (*glob != '?')
46 {
47 if (case_insensitive)
48 {
49 if (tolower(*glob) != tolower(*text))
50 return 0;
51 }
52 else if (*glob != *text)
53 return 0;
54 }
55 glob++;
56 text++;
57 }
58}
59
60/*
61 * Local variables:
62 * c-basic-offset: 4
63 * c-file-style: "Stroustrup"
64 * indent-tabs-mode: nil
65 * End:
66 * vim: shiftwidth=4 tabstop=8 expandtab
67 */
68
int yaz_match_glob2(const char *glob, const char *text, int case_insensitive)
matches a glob expression against text
Definition match_glob.c:27
int yaz_match_glob(const char *glob, const char *text)
matches a glob expression against text
Definition match_glob.c:22
Glob expression matcher.
Header for WRBUF (growing buffer)
Header for memory handling functions.