aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt
diff options
context:
space:
mode:
authorTatsuo Ishii <ishii@postgresql.org>2000-12-11 05:00:18 +0000
committerTatsuo Ishii <ishii@postgresql.org>2000-12-11 05:00:18 +0000
commitd81fd94d400b092b494bf3c9958821628692d48f (patch)
tree4e5f1a94c7c9f78ea5ba4fe87b64d8ab5883045e /src/backend/utils/adt
parente8caadefc4611b236a026068e27009140ea4e5da (diff)
downloadpostgresql-d81fd94d400b092b494bf3c9958821628692d48f.tar.gz
postgresql-d81fd94d400b092b494bf3c9958821628692d48f.zip
Fix ILIKE bug (only in multi-byte case)
Diffstat (limited to 'src/backend/utils/adt')
-rw-r--r--src/backend/utils/adt/like.c45
1 files changed, 22 insertions, 23 deletions
diff --git a/src/backend/utils/adt/like.c b/src/backend/utils/adt/like.c
index 41e86648b87..5df0680a0c4 100644
--- a/src/backend/utils/adt/like.c
+++ b/src/backend/utils/adt/like.c
@@ -11,7 +11,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.42 2000/09/15 18:45:26 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.43 2000/12/11 05:00:18 ishii Exp $
*
*-------------------------------------------------------------------------
*/
@@ -63,35 +63,34 @@ static int wchareq(unsigned char *p1, unsigned char *p2)
* If they match, returns 1 otherwise returns 0.
*--------------------
*/
-#define UCHARMAX 0xff
+#define CHARMAX 0x80
static int iwchareq(unsigned char *p1, unsigned char *p2)
{
- int c1, c2;
+ int c1[2], c2[2];
int l;
- /* short cut. if *p1 and *p2 is lower than UCHARMAX, then
- we assume they are ASCII */
- if (*p1 < UCHARMAX && *p2 < UCHARMAX)
+ /* short cut. if *p1 and *p2 is lower than CHARMAX, then
+ we could assume they are ASCII */
+ if (*p1 < CHARMAX && *p2 < CHARMAX)
return(tolower(*p1) == tolower(*p2));
- if (*p1 < UCHARMAX)
- c1 = tolower(*p1);
- else
- {
- l = pg_mblen(p1);
- (void)pg_mb2wchar_with_len(p1, (pg_wchar *)&c1, l);
- c1 = tolower(c1);
- }
- if (*p2 < UCHARMAX)
- c2 = tolower(*p2);
- else
- {
- l = pg_mblen(p2);
- (void)pg_mb2wchar_with_len(p2, (pg_wchar *)&c2, l);
- c2 = tolower(c2);
- }
- return(c1 == c2);
+ /* if one of them is an ASCII while the other is not, then
+ they must be different characters
+ */
+ else if (*p1 < CHARMAX || *p2 < CHARMAX)
+ return(0);
+
+ /* ok, p1 and p2 are both > CHARMAX, then they must be multi-byte
+ characters
+ */
+ l = pg_mblen(p1);
+ (void)pg_mb2wchar_with_len(p1, (pg_wchar *)c1, l);
+ c1[0] = tolower(c1[0]);
+ l = pg_mblen(p2);
+ (void)pg_mb2wchar_with_len(p2, (pg_wchar *)c2, l);
+ c2[0] = tolower(c2[0]);
+ return(c1[0] == c2[0]);
}
#endif