~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/internal/mf_wcomp.cc

  • Committer: Olaf van der Spek
  • Date: 2011-07-07 12:37:15 UTC
  • mto: This revision was merged to the branch mainline in revision 2385.
  • Revision ID: olafvdspek@gmail.com-20110707123715-3mp9mozbg968vt49
PruneĀ unusedĀ code

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
 
/* Funktions for comparing with wild-cards */
17
 
 
18
16
#include <config.h>
19
17
 
20
18
#include <drizzled/internal/my_sys.h>
21
19
 
22
 
namespace drizzled
23
 
{
24
 
namespace internal
25
 
{
26
 
 
27
 
        /* Test if a string is "comparable" to a wild-card string */
28
 
        /* returns 0 if the strings are "comparable" */
29
 
 
30
 
char wild_many='%';
31
 
char wild_one='_';
32
 
char wild_prefix= '\\';
33
 
 
34
 
int wild_compare(const char *str, const char *wildstr, bool str_is_pattern)
35
 
{
36
 
  char cmp;
37
 
 
38
 
  while (*wildstr)
39
 
  {
40
 
    while (*wildstr && *wildstr != wild_many && *wildstr != wild_one)
41
 
    {
42
 
      if (*wildstr == wild_prefix && wildstr[1])
43
 
      {
44
 
        wildstr++;
45
 
        if (str_is_pattern && *str++ != wild_prefix)
46
 
          return 1;
47
 
      }
48
 
      if (*wildstr++ != *str++)
49
 
        return 1;
50
 
    }
51
 
    if (! *wildstr )
52
 
      return(*str != 0);
53
 
    if (*wildstr++ == wild_one)
54
 
    {
55
 
      if (! *str || (str_is_pattern && *str == wild_many))
56
 
        return 1;                     /* One char; skip */
57
 
      if (*str++ == wild_prefix && str_is_pattern && *str)
58
 
        str++;
59
 
    }
60
 
    else
61
 
    {                                           /* Found '*' */
62
 
      while (str_is_pattern && *str == wild_many)
63
 
        str++;
64
 
      for (; *wildstr ==  wild_many || *wildstr == wild_one; wildstr++)
65
 
        if (*wildstr == wild_many)
66
 
        {
67
 
          while (str_is_pattern && *str == wild_many)
68
 
            str++;
69
 
        }
70
 
        else
71
 
        {
72
 
          if (str_is_pattern && *str == wild_prefix && str[1])
73
 
            str+=2;
74
 
          else if (! *str++)
75
 
            return (1);
76
 
        }
77
 
      if (!*wildstr)
78
 
        return 0;               /* '*' as last char: OK */
79
 
      if ((cmp= *wildstr) == wild_prefix && wildstr[1] && !str_is_pattern)
80
 
        cmp=wildstr[1];
81
 
      for (;;str++)
82
 
      {
83
 
        while (*str && *str != cmp)
84
 
          str++;
85
 
        if (!*str)
86
 
          return (1);
87
 
        if (wild_compare(str,wildstr,str_is_pattern) == 0)
88
 
          return (0);
89
 
      }
90
 
      /* We will never come here */
91
 
    }
92
 
  }
93
 
  return (*str != 0);
94
 
} /* wild_compare */
 
20
namespace drizzled {
 
21
namespace internal {
 
22
 
 
23
const char wild_many= '%';
 
24
const char wild_one= '_';
 
25
const char wild_prefix= '\\';
95
26
 
96
27
} /* namespace internal */
97
28
} /* namespace drizzled */