* 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 $
*
*-------------------------------------------------------------------------
*/
*/
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 == '%'))
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.
}
/*
- * 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;
}
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() */
* 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 == '%'))
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.
}
/*
- * 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;
}
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() */
do_like_escape(text *pat, text *esc)
{
text *result;
- unsigned char *p,
+ char *p,
*e,
*r;
int plen,
if (elen == 0)
{
-
/*
* No escape character is wanted. Double any backslashes in the
* pattern to make them act like ordinary characters.
}
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);
/*
}
/*
- * 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)
}
}
- VARATT_SIZEP(result) = r - ((unsigned char *) result);
+ VARATT_SIZEP(result) = r - ((char *) result);
return result;
}