1 /* $Id: rob_regexp.c,v 1.1 2007-10-23 12:26:26 adam Exp $
2 Copyright (C) 1995-2007
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 \brief Rob Pike's regular expresion parser
26 Taken verbatim from Beautiful code.. ANSIfied a bit.
35 #include "rob_regexp.h"
36 #include <yaz/xmalloc.h>
37 #include <yaz/wrbuf.h>
40 static int matchhere(const char *regexp, const char *text);
41 static int matchstar(int c, const char *regexp, const char *text);
43 int zebra_rob_regexp(const char *regexp, const char *text)
46 return matchhere(regexp+1, text);
49 if (matchhere(regexp, text))
56 static int matchhere(const char *regexp, const char *text)
58 if (regexp[0] == '\0')
61 return matchstar(regexp[0], regexp+2, text);
62 if (regexp[0] == '$' && regexp[1] == '\0')
64 if (*text && (regexp[0] == '.' || regexp[0] == *text))
65 return matchhere(regexp+1, text+1);
69 static int matchstar(int c, const char *regexp, const char *text)
73 if (matchhere(regexp, text))
76 while (*text && (*text++ == c || c == '.'));
84 * indent-tabs-mode: nil
86 * vim: shiftwidth=4 tabstop=8 expandtab