Clean up code to remove the explicit backslash cruft.
authorThomas G. Lockhart <lockhart@fourpalms.org>
Mon, 7 Aug 2000 01:45:00 +0000 (01:45 +0000)
committerThomas G. Lockhart <lockhart@fourpalms.org>
Mon, 7 Aug 2000 01:45:00 +0000 (01:45 +0000)
If the backslash default is still wanted, just pass a backslash
 to MatchText() for the two-parameter callable routines.

src/backend/utils/adt/like.c

index 058fb1d9656655983b2a4c18aa15b9859be62286..0be559598d54a4a06a865928a947f762082b8f67 100644 (file)
  * 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);