Commit 12e1c9ef authored by Thomas G. Lockhart's avatar Thomas G. Lockhart

Clean up code to remove the explicit backslash cruft.

If the backslash default is still wanted, just pass a backslash
 to MatchText() for the two-parameter callable routines.
parent 371a485d
...@@ -11,12 +11,12 @@ ...@@ -11,12 +11,12 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.38 2000/08/06 18:05:41 thomas Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.39 2000/08/07 01:45:00 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres.h" #include "postgres.h"
#include <ctype.h>
#include "mb/pg_wchar.h" #include "mb/pg_wchar.h"
#include "utils/builtins.h" #include "utils/builtins.h"
...@@ -307,59 +307,51 @@ MatchText(pg_wchar * t, int tlen, pg_wchar * p, int plen, char *e) ...@@ -307,59 +307,51 @@ MatchText(pg_wchar * t, int tlen, pg_wchar * p, int plen, char *e)
if ((plen <= 0) || (*t != *p)) if ((plen <= 0) || (*t != *p))
return LIKE_FALSE; return LIKE_FALSE;
} }
else else if (*p == '%')
{ {
switch (*p) /* %% is the same as % according to the SQL standard */
/* Advance past all %'s */
while ((plen > 0) && (*p == '%'))
NextChar(p, plen);
/* Trailing percent matches everything. */
if (plen <= 0)
return LIKE_TRUE;
/*
* Otherwise, scan for a text position at which we can
* match the rest of the pattern.
*/
while (tlen > 0)
{ {
case '\\': /*
/* Literal match with following character. */ * Optimization to prevent most recursion: don't
NextChar(p, plen); * recurse unless first pattern char might match this
/* FALLTHROUGH */ * text char.
default: */
if (*t != *p) if ((*t == *p) || (*p == '_')
return LIKE_FALSE; || ((e != NULL) && (*p == *e)))
break; {
case '_': int matched = MatchText(t, tlen, p, plen, e);
/* Match any single character. */
break; if (matched != LIKE_FALSE)
case '%': return matched; /* TRUE or ABORT */
/* %% is the same as % according to the SQL standard */ }
/* Advance past all %'s */
while ((plen > 0) && (*p == '%')) NextChar(t, tlen);
NextChar(p, plen);
/* Trailing percent matches everything. */
if (plen <= 0)
return LIKE_TRUE;
/*
* Otherwise, scan for a text position at which we can
* match the rest of the pattern.
*/
while (tlen > 0)
{
/*
* Optimization to prevent most recursion: don't
* recurse unless first pattern char might match this
* text char.
*/
if ((*t == *p) || (*p == '\\') || (*p == '_')
|| ((e != NULL) && (*p == *e)))
{
int matched = MatchText(t, tlen, p, plen, e);
if (matched != LIKE_FALSE)
return matched; /* TRUE or ABORT */
}
NextChar(t, tlen);
}
/*
* End of text with no match, so no point in trying later
* places to start matching this pattern.
*/
return LIKE_ABORT;
} }
/*
* End of text with no match, so no point in trying later
* places to start matching this pattern.
*/
return LIKE_ABORT;
}
else if ((*p != '_') && (*t != *p))
{
/* Not the single-character wildcard and no explicit match?
* Then time to quit...
*/
return LIKE_FALSE;
} }
NextChar(t, tlen); NextChar(t, tlen);
...@@ -404,59 +396,48 @@ MatchTextLower(pg_wchar * t, int tlen, pg_wchar * p, int plen, char *e) ...@@ -404,59 +396,48 @@ MatchTextLower(pg_wchar * t, int tlen, pg_wchar * p, int plen, char *e)
if ((plen <= 0) || (tolower(*t) != tolower(*p))) if ((plen <= 0) || (tolower(*t) != tolower(*p)))
return LIKE_FALSE; return LIKE_FALSE;
} }
else else if (*p == '%')
{ {
switch (*p) /* %% is the same as % according to the SQL standard */
/* Advance past all %'s */
while ((plen > 0) && (*p == '%'))
NextChar(p, plen);
/* Trailing percent matches everything. */
if (plen <= 0)
return LIKE_TRUE;
/*
* Otherwise, scan for a text position at which we can
* match the rest of the pattern.
*/
while (tlen > 0)
{ {
case '\\': /*
/* Literal match with following character. */ * Optimization to prevent most recursion: don't
NextChar(p, plen); * recurse unless first pattern char might match this
/* FALLTHROUGH */ * text char.
default: */
if (tolower(*t) != tolower(*p)) if ((tolower(*t) == tolower(*p)) || (*p == '_')
return LIKE_FALSE; || ((e != NULL) && (tolower(*p) == tolower(*e))))
break; {
case '_': int matched = MatchText(t, tlen, p, plen, e);
/* Match any single character. */
break; if (matched != LIKE_FALSE)
case '%': return matched; /* TRUE or ABORT */
/* %% is the same as % according to the SQL standard */ }
/* Advance past all %'s */
while ((plen > 0) && (*p == '%')) NextChar(t, tlen);
NextChar(p, plen);
/* Trailing percent matches everything. */
if (plen <= 0)
return LIKE_TRUE;
/*
* Otherwise, scan for a text position at which we can
* match the rest of the pattern.
*/
while (tlen > 0)
{
/*
* Optimization to prevent most recursion: don't
* recurse unless first pattern char might match this
* text char.
*/
if ((tolower(*t) == tolower(*p)) || (*p == '\\') || (*p == '_')
|| ((e != NULL) && (tolower(*p) == tolower(*e))))
{
int matched = MatchText(t, tlen, p, plen, e);
if (matched != LIKE_FALSE)
return matched; /* TRUE or ABORT */
}
NextChar(t, tlen);
}
/*
* End of text with no match, so no point in trying later
* places to start matching this pattern.
*/
return LIKE_ABORT;
} }
/*
* End of text with no match, so no point in trying later
* places to start matching this pattern.
*/
return LIKE_ABORT;
}
else if ((*p != '_') && (tolower(*t) != tolower(*p)))
{
return LIKE_FALSE;
} }
NextChar(t, tlen); NextChar(t, tlen);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment