]> granicus.if.org Git - postgresql/blobdiff - src/backend/utils/adt/like_match.c
Message style improvements
[postgresql] / src / backend / utils / adt / like_match.c
index f13b8fea05c8546b432de5596249c6724f607247..144f408b98a313d2b8b2e1f8222089fbc38617a4 100644 (file)
@@ -3,8 +3,9 @@
  * like_match.c
  *       like expression handling internal code.
  *
- * This file is included by like.c *twice* if multibyte is enabled.
- * This is for an optimization of single byte encodings.
+ * This file is included by like.c *twice*, to provide an optimization
+ * for single-byte encodings.
+ *
  * Before the inclusion, we need to define following macros:
  *
  * CHAREQ
  * MatchTextIC (MBMatchTextIC)
  * do_like_escape (MB_do_like_escape)
  *
- * Copyright (c) 1996-2001, PostgreSQL Global Development Group
+ * Copyright (c) 1996-2006, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *     $Header: /cvsroot/pgsql/src/backend/utils/adt/like_match.c,v 1.1 2001/10/04 02:15:47 ishii Exp $
+ *     $PostgreSQL: pgsql/src/backend/utils/adt/like_match.c,v 1.13 2006/03/05 15:58:42 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -70,7 +71,7 @@
  */
 
 static int
-MatchText(unsigned char *t, int tlen, unsigned char *p, int plen)
+MatchText(char *t, int tlen, char *p, int plen)
 {
        /* Fast path for match-everything pattern */
        if ((plen == 1) && (*p == '%'))
@@ -96,12 +97,11 @@ MatchText(unsigned char *t, int tlen, unsigned char *p, int plen)
                                return LIKE_TRUE;
 
                        /*
-                        * Otherwise, scan for a text position at which we can match
-                        * the rest of the pattern.
+                        * 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.
@@ -118,17 +118,16 @@ MatchText(unsigned char *t, int tlen, unsigned char *p, int plen)
                        }
 
                        /*
-                        * End of text with no match, so no point in trying later
-                        * places to start matching this pattern.
+                        * End of text with no match, so no point in trying later places
+                        * to start matching this pattern.
                         */
                        return LIKE_ABORT;
                }
                else if ((*p != '_') && !CHAREQ(t, p))
                {
-
                        /*
-                        * Not the single-character wildcard and no explicit match?
-                        * Then time to quit...
+                        * Not the single-character wildcard and no explicit match? Then
+                        * time to quit...
                         */
                        return LIKE_FALSE;
                }
@@ -148,8 +147,8 @@ MatchText(unsigned char *t, int tlen, unsigned char *p, int plen)
                return LIKE_TRUE;
 
        /*
-        * End of text with no match, so no point in trying later places to
-        * start matching this pattern.
+        * End of text with no match, so no point in trying later places to start
+        * matching this pattern.
         */
        return LIKE_ABORT;
 }      /* MatchText() */
@@ -158,7 +157,7 @@ MatchText(unsigned char *t, int tlen, unsigned char *p, int plen)
  * Same as above, but ignore case
  */
 static int
-MatchTextIC(unsigned char *t, int tlen, unsigned char *p, int plen)
+MatchTextIC(char *t, int tlen, char *p, int plen)
 {
        /* Fast path for match-everything pattern */
        if ((plen == 1) && (*p == '%'))
@@ -184,12 +183,11 @@ MatchTextIC(unsigned char *t, int tlen, unsigned char *p, int plen)
                                return LIKE_TRUE;
 
                        /*
-                        * Otherwise, scan for a text position at which we can match
-                        * the rest of the pattern.
+                        * 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.
@@ -206,17 +204,16 @@ MatchTextIC(unsigned char *t, int tlen, unsigned char *p, int plen)
                        }
 
                        /*
-                        * End of text with no match, so no point in trying later
-                        * places to start matching this pattern.
+                        * End of text with no match, so no point in trying later places
+                        * to start matching this pattern.
                         */
                        return LIKE_ABORT;
                }
                else if ((*p != '_') && !ICHAREQ(t, p))
                {
-
                        /*
-                        * Not the single-character wildcard and no explicit match?
-                        * Then time to quit...
+                        * Not the single-character wildcard and no explicit match? Then
+                        * time to quit...
                         */
                        return LIKE_FALSE;
                }
@@ -236,8 +233,8 @@ MatchTextIC(unsigned char *t, int tlen, unsigned char *p, int plen)
                return LIKE_TRUE;
 
        /*
-        * End of text with no match, so no point in trying later places to
-        * start matching this pattern.
+        * End of text with no match, so no point in trying later places to start
+        * matching this pattern.
         */
        return LIKE_ABORT;
 }      /* MatchTextIC() */
@@ -250,7 +247,7 @@ static text *
 do_like_escape(text *pat, text *esc)
 {
        text       *result;
-       unsigned char *p,
+       char       *p,
                           *e,
                           *r;
        int                     plen,
@@ -271,7 +268,6 @@ do_like_escape(text *pat, text *esc)
 
        if (elen == 0)
        {
-
                /*
                 * No escape character is wanted.  Double any backslashes in the
                 * pattern to make them act like ordinary characters.
@@ -285,13 +281,16 @@ do_like_escape(text *pat, text *esc)
        }
        else
        {
-
                /*
                 * The specified escape must be only a single character.
                 */
                NextChar(e, elen);
                if (elen != 0)
-                       elog(ERROR, "ESCAPE string must be empty or one character");
+                       ereport(ERROR,
+                                       (errcode(ERRCODE_INVALID_ESCAPE_SEQUENCE),
+                                        errmsg("invalid escape string"),
+                                 errhint("Escape string must be empty or one character.")));
+
                e = VARDATA(esc);
 
                /*
@@ -304,9 +303,9 @@ do_like_escape(text *pat, text *esc)
                }
 
                /*
-                * Otherwise, convert occurrences of the specified escape
-                * character to '\', and double occurrences of '\' --- unless they
-                * immediately follow an escape character!
+                * Otherwise, convert occurrences of the specified escape character to
+                * '\', and double occurrences of '\' --- unless they immediately
+                * follow an escape character!
                 */
                afterescape = false;
                while (plen > 0)
@@ -333,7 +332,7 @@ do_like_escape(text *pat, text *esc)
                }
        }
 
-       VARATT_SIZEP(result) = r - ((unsigned char *) result);
+       VARATT_SIZEP(result) = r - ((char *) result);
 
        return result;
 }