aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas G. Lockhart <lockhart@fourpalms.org>2000-08-07 01:45:00 +0000
committerThomas G. Lockhart <lockhart@fourpalms.org>2000-08-07 01:45:00 +0000
commit12e1c9efad7dc59a285f801fdff7204af1f7de43 (patch)
treec410bb418613e1eabd992d157dc0e89b6a784697 /src
parent371a485dba0801446c0c25a38a5c6353bfb12023 (diff)
downloadpostgresql-12e1c9efad7dc59a285f801fdff7204af1f7de43.tar.gz
postgresql-12e1c9efad7dc59a285f801fdff7204af1f7de43.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/adt/like.c185
1 files changed, 83 insertions, 102 deletions
diff --git a/src/backend/utils/adt/like.c b/src/backend/utils/adt/like.c
index 058fb1d9656..0be559598d5 100644
--- a/src/backend/utils/adt/like.c
+++ b/src/backend/utils/adt/like.c
@@ -11,12 +11,12 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* 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 <ctype.h>
#include "mb/pg_wchar.h"
#include "utils/builtins.h"
@@ -307,59 +307,51 @@ MatchText(pg_wchar * t, int tlen, pg_wchar * p, int plen, char *e)
if ((plen <= 0) || (*t != *p))
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. */
- NextChar(p, plen);
- /* FALLTHROUGH */
- default:
- if (*t != *p)
- return LIKE_FALSE;
- break;
- case '_':
- /* Match any single character. */
- break;
- case '%':
- /* %% 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)
- {
- /*
- * 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;
+ /*
+ * Optimization to prevent most recursion: don't
+ * recurse unless first pattern char might match this
+ * text char.
+ */
+ if ((*t == *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;
+ }
+ else if ((*p != '_') && (*t != *p))
+ {
+ /* Not the single-character wildcard and no explicit match?
+ * Then time to quit...
+ */
+ return LIKE_FALSE;
}
NextChar(t, tlen);
@@ -404,59 +396,48 @@ MatchTextLower(pg_wchar * t, int tlen, pg_wchar * p, int plen, char *e)
if ((plen <= 0) || (tolower(*t) != tolower(*p)))
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. */
- NextChar(p, plen);
- /* FALLTHROUGH */
- default:
- if (tolower(*t) != tolower(*p))
- return LIKE_FALSE;
- break;
- case '_':
- /* Match any single character. */
- break;
- case '%':
- /* %% 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)
- {
- /*
- * 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;
+ /*
+ * Optimization to prevent most recursion: don't
+ * recurse unless first pattern char might match this
+ * text char.
+ */
+ if ((tolower(*t) == tolower(*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;
+ }
+ else if ((*p != '_') && (tolower(*t) != tolower(*p)))
+ {
+ return LIKE_FALSE;
}
NextChar(t, tlen);