~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
13
   along with this program; if not, write to the Free Software
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
16
/* Funktions for comparing with wild-cards */
17
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
18
#include "config.h"
19
20
#include "drizzled/internal/my_sys.h"
21
22
namespace drizzled
23
{
24
namespace internal
25
{
1 by brian
clean slate
26
27
	/* Test if a string is "comparable" to a wild-card string */
28
	/* returns 0 if the strings are "comparable" */
29
909 by Brian Aker
Remove the need for unireg init
30
char wild_many='%';
31
char wild_one='_';
32
char wild_prefix= '\\';
1 by brian
clean slate
33
34
int wild_compare(register const char *str, register const char *wildstr,
154 by Brian Aker
Removed oddball types in my_global.h
35
                 bool str_is_pattern)
1 by brian
clean slate
36
{
37
  char cmp;
38
39
  while (*wildstr)
40
  {
41
    while (*wildstr && *wildstr != wild_many && *wildstr != wild_one)
42
    {
43
      if (*wildstr == wild_prefix && wildstr[1])
44
      {
45
	wildstr++;
46
        if (str_is_pattern && *str++ != wild_prefix)
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
47
          return(1);
1 by brian
clean slate
48
      }
49
      if (*wildstr++ != *str++)
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
50
        return(1);
1 by brian
clean slate
51
    }
52
    if (! *wildstr )
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
53
      return(*str != 0);
1 by brian
clean slate
54
    if (*wildstr++ == wild_one)
55
    {
56
      if (! *str || (str_is_pattern && *str == wild_many))
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
57
        return(1);                     /* One char; skip */
1 by brian
clean slate
58
      if (*str++ == wild_prefix && str_is_pattern && *str)
59
        str++;
60
    }
61
    else
62
    {						/* Found '*' */
63
      while (str_is_pattern && *str == wild_many)
64
        str++;
65
      for (; *wildstr ==  wild_many || *wildstr == wild_one; wildstr++)
66
        if (*wildstr == wild_many)
67
        {
68
          while (str_is_pattern && *str == wild_many)
69
            str++;
70
        }
71
        else
72
        {
73
          if (str_is_pattern && *str == wild_prefix && str[1])
74
            str+=2;
75
          else if (! *str++)
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
76
            return (1);
1 by brian
clean slate
77
        }
78
      if (!*wildstr)
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
79
        return(0);		/* '*' as last char: OK */
1 by brian
clean slate
80
      if ((cmp= *wildstr) == wild_prefix && wildstr[1] && !str_is_pattern)
81
        cmp=wildstr[1];
82
      for (;;str++)
83
      {
84
        while (*str && *str != cmp)
85
          str++;
86
        if (!*str)
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
87
          return (1);
1 by brian
clean slate
88
	if (wild_compare(str,wildstr,str_is_pattern) == 0)
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
89
          return (0);
1 by brian
clean slate
90
      }
91
      /* We will never come here */
92
    }
93
  }
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
94
  return (*str != 0);
1 by brian
clean slate
95
} /* wild_compare */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
96
97
} /* namespace internal */
98
} /* namespace drizzled */