|
|
|
@ -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,22 +307,8 @@ MatchText(pg_wchar * t, int tlen, pg_wchar * p, int plen, char *e) |
|
|
|
|
if ((plen <= 0) || (*t != *p)) |
|
|
|
|
return LIKE_FALSE; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
switch (*p) |
|
|
|
|
else if (*p == '%') |
|
|
|
|
{ |
|
|
|
|
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 == '%')) |
|
|
|
@ -342,7 +328,7 @@ MatchText(pg_wchar * t, int tlen, pg_wchar * p, int plen, char *e) |
|
|
|
|
* recurse unless first pattern char might match this |
|
|
|
|
* text char. |
|
|
|
|
*/ |
|
|
|
|
if ((*t == *p) || (*p == '\\') || (*p == '_') |
|
|
|
|
if ((*t == *p) || (*p == '_') |
|
|
|
|
|| ((e != NULL) && (*p == *e))) |
|
|
|
|
{ |
|
|
|
|
int matched = MatchText(t, tlen, p, plen, e); |
|
|
|
@ -360,6 +346,12 @@ MatchText(pg_wchar * t, int tlen, pg_wchar * p, int plen, char *e) |
|
|
|
|
*/ |
|
|
|
|
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,22 +396,8 @@ MatchTextLower(pg_wchar * t, int tlen, pg_wchar * p, int plen, char *e) |
|
|
|
|
if ((plen <= 0) || (tolower(*t) != tolower(*p))) |
|
|
|
|
return LIKE_FALSE; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
switch (*p) |
|
|
|
|
else if (*p == '%') |
|
|
|
|
{ |
|
|
|
|
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 == '%')) |
|
|
|
@ -439,7 +417,7 @@ MatchTextLower(pg_wchar * t, int tlen, pg_wchar * p, int plen, char *e) |
|
|
|
|
* recurse unless first pattern char might match this |
|
|
|
|
* text char. |
|
|
|
|
*/ |
|
|
|
|
if ((tolower(*t) == tolower(*p)) || (*p == '\\') || (*p == '_') |
|
|
|
|
if ((tolower(*t) == tolower(*p)) || (*p == '_') |
|
|
|
|
|| ((e != NULL) && (tolower(*p) == tolower(*e)))) |
|
|
|
|
{ |
|
|
|
|
int matched = MatchText(t, tlen, p, plen, e); |
|
|
|
@ -457,6 +435,9 @@ MatchTextLower(pg_wchar * t, int tlen, pg_wchar * p, int plen, char *e) |
|
|
|
|
*/ |
|
|
|
|
return LIKE_ABORT; |
|
|
|
|
} |
|
|
|
|
else if ((*p != '_') && (tolower(*t) != tolower(*p))) |
|
|
|
|
{ |
|
|
|
|
return LIKE_FALSE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
NextChar(t, tlen); |
|
|
|
|