|
11 | 11 | * Portions Copyright (c) 1994, Regents of the University of California
|
12 | 12 | *
|
13 | 13 | * IDENTIFICATION
|
14 |
| - *$Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.38 2000/08/06 18:05:41 thomas Exp $ |
| 14 | + *$Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.39 2000/08/07 01:45:00 thomas Exp $ |
15 | 15 | *
|
16 | 16 | *-------------------------------------------------------------------------
|
17 | 17 | */
|
18 | 18 | #include"postgres.h"
|
19 |
| - |
| 19 | +#include<ctype.h> |
20 | 20 | #include"mb/pg_wchar.h"
|
21 | 21 | #include"utils/builtins.h"
|
22 | 22 |
|
@@ -307,59 +307,51 @@ MatchText(pg_wchar * t, int tlen, pg_wchar * p, int plen, char *e)
|
307 | 307 | if ((plen <=0)|| (*t!=*p))
|
308 | 308 | returnLIKE_FALSE;
|
309 | 309 | }
|
310 |
| -else |
| 310 | +elseif (*p=='%') |
311 | 311 | {
|
312 |
| -switch (*p) |
| 312 | +/* %% is the same as % according to the SQL standard */ |
| 313 | +/* Advance past all %'s */ |
| 314 | +while ((plen>0)&& (*p=='%')) |
| 315 | +NextChar(p,plen); |
| 316 | +/* Trailing percent matches everything. */ |
| 317 | +if (plen <=0) |
| 318 | +returnLIKE_TRUE; |
| 319 | + |
| 320 | +/* |
| 321 | + * Otherwise, scan for a text position at which we can |
| 322 | + * match the rest of the pattern. |
| 323 | + */ |
| 324 | +while (tlen>0) |
313 | 325 | {
|
314 |
| -case'\\': |
315 |
| -/* Literal match with following character. */ |
316 |
| -NextChar(p,plen); |
317 |
| -/* FALLTHROUGH */ |
318 |
| -default: |
319 |
| -if (*t!=*p) |
320 |
| -returnLIKE_FALSE; |
321 |
| -break; |
322 |
| -case'_': |
323 |
| -/* Match any single character. */ |
324 |
| -break; |
325 |
| -case'%': |
326 |
| -/* %% is the same as % according to the SQL standard */ |
327 |
| -/* Advance past all %'s */ |
328 |
| -while ((plen>0)&& (*p=='%')) |
329 |
| -NextChar(p,plen); |
330 |
| -/* Trailing percent matches everything. */ |
331 |
| -if (plen <=0) |
332 |
| -returnLIKE_TRUE; |
333 |
| - |
334 |
| -/* |
335 |
| - * Otherwise, scan for a text position at which we can |
336 |
| - * match the rest of the pattern. |
337 |
| - */ |
338 |
| -while (tlen>0) |
339 |
| -{ |
340 |
| -/* |
341 |
| - * Optimization to prevent most recursion: don't |
342 |
| - * recurse unless first pattern char might match this |
343 |
| - * text char. |
344 |
| - */ |
345 |
| -if ((*t==*p)|| (*p=='\\')|| (*p=='_') |
346 |
| -|| ((e!=NULL)&& (*p==*e))) |
347 |
| -{ |
348 |
| -intmatched=MatchText(t,tlen,p,plen,e); |
349 |
| - |
350 |
| -if (matched!=LIKE_FALSE) |
351 |
| -returnmatched;/* TRUE or ABORT */ |
352 |
| -} |
353 |
| - |
354 |
| -NextChar(t,tlen); |
355 |
| -} |
356 |
| - |
357 |
| -/* |
358 |
| - * End of text with no match, so no point in trying later |
359 |
| - * places to start matching this pattern. |
360 |
| - */ |
361 |
| -returnLIKE_ABORT; |
| 326 | +/* |
| 327 | + * Optimization to prevent most recursion: don't |
| 328 | + * recurse unless first pattern char might match this |
| 329 | + * text char. |
| 330 | + */ |
| 331 | +if ((*t==*p)|| (*p=='_') |
| 332 | +|| ((e!=NULL)&& (*p==*e))) |
| 333 | +{ |
| 334 | +intmatched=MatchText(t,tlen,p,plen,e); |
| 335 | + |
| 336 | +if (matched!=LIKE_FALSE) |
| 337 | +returnmatched;/* TRUE or ABORT */ |
| 338 | +} |
| 339 | + |
| 340 | +NextChar(t,tlen); |
362 | 341 | }
|
| 342 | + |
| 343 | +/* |
| 344 | + * End of text with no match, so no point in trying later |
| 345 | + * places to start matching this pattern. |
| 346 | + */ |
| 347 | +returnLIKE_ABORT; |
| 348 | +} |
| 349 | +elseif ((*p!='_')&& (*t!=*p)) |
| 350 | +{ |
| 351 | +/* Not the single-character wildcard and no explicit match? |
| 352 | + * Then time to quit... |
| 353 | + */ |
| 354 | +returnLIKE_FALSE; |
363 | 355 | }
|
364 | 356 |
|
365 | 357 | NextChar(t,tlen);
|
@@ -404,59 +396,48 @@ MatchTextLower(pg_wchar * t, int tlen, pg_wchar * p, int plen, char *e)
|
404 | 396 | if ((plen <=0)|| (tolower(*t)!=tolower(*p)))
|
405 | 397 | returnLIKE_FALSE;
|
406 | 398 | }
|
407 |
| -else |
| 399 | +elseif (*p=='%') |
408 | 400 | {
|
409 |
| -switch (*p) |
| 401 | +/* %% is the same as % according to the SQL standard */ |
| 402 | +/* Advance past all %'s */ |
| 403 | +while ((plen>0)&& (*p=='%')) |
| 404 | +NextChar(p,plen); |
| 405 | +/* Trailing percent matches everything. */ |
| 406 | +if (plen <=0) |
| 407 | +returnLIKE_TRUE; |
| 408 | + |
| 409 | +/* |
| 410 | + * Otherwise, scan for a text position at which we can |
| 411 | + * match the rest of the pattern. |
| 412 | + */ |
| 413 | +while (tlen>0) |
410 | 414 | {
|
411 |
| -case'\\': |
412 |
| -/* Literal match with following character. */ |
413 |
| -NextChar(p,plen); |
414 |
| -/* FALLTHROUGH */ |
415 |
| -default: |
416 |
| -if (tolower(*t)!=tolower(*p)) |
417 |
| -returnLIKE_FALSE; |
418 |
| -break; |
419 |
| -case'_': |
420 |
| -/* Match any single character. */ |
421 |
| -break; |
422 |
| -case'%': |
423 |
| -/* %% is the same as % according to the SQL standard */ |
424 |
| -/* Advance past all %'s */ |
425 |
| -while ((plen>0)&& (*p=='%')) |
426 |
| -NextChar(p,plen); |
427 |
| -/* Trailing percent matches everything. */ |
428 |
| -if (plen <=0) |
429 |
| -returnLIKE_TRUE; |
430 |
| - |
431 |
| -/* |
432 |
| - * Otherwise, scan for a text position at which we can |
433 |
| - * match the rest of the pattern. |
434 |
| - */ |
435 |
| -while (tlen>0) |
436 |
| -{ |
437 |
| -/* |
438 |
| - * Optimization to prevent most recursion: don't |
439 |
| - * recurse unless first pattern char might match this |
440 |
| - * text char. |
441 |
| - */ |
442 |
| -if ((tolower(*t)==tolower(*p))|| (*p=='\\')|| (*p=='_') |
443 |
| -|| ((e!=NULL)&& (tolower(*p)==tolower(*e)))) |
444 |
| -{ |
445 |
| -intmatched=MatchText(t,tlen,p,plen,e); |
446 |
| - |
447 |
| -if (matched!=LIKE_FALSE) |
448 |
| -returnmatched;/* TRUE or ABORT */ |
449 |
| -} |
450 |
| - |
451 |
| -NextChar(t,tlen); |
452 |
| -} |
453 |
| - |
454 |
| -/* |
455 |
| - * End of text with no match, so no point in trying later |
456 |
| - * places to start matching this pattern. |
457 |
| - */ |
458 |
| -returnLIKE_ABORT; |
| 415 | +/* |
| 416 | + * Optimization to prevent most recursion: don't |
| 417 | + * recurse unless first pattern char might match this |
| 418 | + * text char. |
| 419 | + */ |
| 420 | +if ((tolower(*t)==tolower(*p))|| (*p=='_') |
| 421 | +|| ((e!=NULL)&& (tolower(*p)==tolower(*e)))) |
| 422 | +{ |
| 423 | +intmatched=MatchText(t,tlen,p,plen,e); |
| 424 | + |
| 425 | +if (matched!=LIKE_FALSE) |
| 426 | +returnmatched;/* TRUE or ABORT */ |
| 427 | +} |
| 428 | + |
| 429 | +NextChar(t,tlen); |
459 | 430 | }
|
| 431 | + |
| 432 | +/* |
| 433 | + * End of text with no match, so no point in trying later |
| 434 | + * places to start matching this pattern. |
| 435 | + */ |
| 436 | +returnLIKE_ABORT; |
| 437 | +} |
| 438 | +elseif ((*p!='_')&& (tolower(*t)!=tolower(*p))) |
| 439 | +{ |
| 440 | +returnLIKE_FALSE; |
460 | 441 | }
|
461 | 442 |
|
462 | 443 | NextChar(t,tlen);
|
|