PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
like.c File Reference
#include "postgres.h"
#include <ctype.h>
#include "catalog/pg_collation.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "utils/builtins.h"
#include "utils/pg_locale.h"
#include "like_match.c"
Include dependency graph for like.c:

Go to the source code of this file.

Macros

#define LIKE_TRUE   1
 
#define LIKE_FALSE   0
 
#define LIKE_ABORT   (-1)
 
#define NextByte(p, plen)   ((p)++, (plen)--)
 
#define CHAREQ(p1, p2)   wchareq((p1), (p2))
 
#define NextChar(p, plen)   do { int __l = pg_mblen(p); (p) +=__l; (plen) -=__l; } while (0)
 
#define CopyAdvChar(dst, src, srclen)
 
#define MatchText   MB_MatchText
 
#define do_like_escape   MB_do_like_escape
 
#define CHAREQ(p1, p2)   (*(p1) == *(p2))
 
#define NextChar(p, plen)   NextByte((p), (plen))
 
#define CopyAdvChar(dst, src, srclen)   (*(dst)++ = *(src)++, (srclen)--)
 
#define MatchText   SB_MatchText
 
#define do_like_escape   SB_do_like_escape
 
#define MATCH_LOWER(t)   SB_lower_char((unsigned char) (t), locale, locale_is_c)
 
#define NextChar(p, plen)   NextByte((p), (plen))
 
#define MatchText   SB_IMatchText
 
#define NextChar(p, plen)   do { (p)++; (plen)--; } while ((plen) > 0 && (*(p) & 0xC0) == 0x80 )
 
#define MatchText   UTF8_MatchText
 

Functions

static int SB_MatchText (char *t, int tlen, char *p, int plen, pg_locale_t locale, bool locale_is_c)
 
static textSB_do_like_escape (text *, text *)
 
static int MB_MatchText (char *t, int tlen, char *p, int plen, pg_locale_t locale, bool locale_is_c)
 
static textMB_do_like_escape (text *, text *)
 
static int UTF8_MatchText (char *t, int tlen, char *p, int plen, pg_locale_t locale, bool locale_is_c)
 
static int SB_IMatchText (char *t, int tlen, char *p, int plen, pg_locale_t locale, bool locale_is_c)
 
static int GenericMatchText (char *s, int slen, char *p, int plen)
 
static int Generic_Text_IC_like (text *str, text *pat, Oid collation)
 
static int wchareq (char *p1, char *p2)
 
static char SB_lower_char (unsigned char c, pg_locale_t locale, bool locale_is_c)
 
Datum namelike (PG_FUNCTION_ARGS)
 
Datum namenlike (PG_FUNCTION_ARGS)
 
Datum textlike (PG_FUNCTION_ARGS)
 
Datum textnlike (PG_FUNCTION_ARGS)
 
Datum bytealike (PG_FUNCTION_ARGS)
 
Datum byteanlike (PG_FUNCTION_ARGS)
 
Datum nameiclike (PG_FUNCTION_ARGS)
 
Datum nameicnlike (PG_FUNCTION_ARGS)
 
Datum texticlike (PG_FUNCTION_ARGS)
 
Datum texticnlike (PG_FUNCTION_ARGS)
 
Datum like_escape (PG_FUNCTION_ARGS)
 
Datum like_escape_bytea (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

#define CHAREQ (   p1,
  p2 
)    wchareq((p1), (p2))

Definition at line 125 of file like.c.

#define CHAREQ (   p1,
  p2 
)    (*(p1) == *(p2))

Definition at line 125 of file like.c.

#define CopyAdvChar (   dst,
  src,
  srclen 
)
Value:
do { int __l = pg_mblen(src); \
(srclen) -= __l; \
while (__l-- > 0) \
*(dst)++ = *(src)++; \
} while (0)
int pg_mblen(const char *mbstr)
Definition: mbutils.c:771

Definition at line 127 of file like.c.

#define CopyAdvChar (   dst,
  src,
  srclen 
)    (*(dst)++ = *(src)++, (srclen)--)

Definition at line 127 of file like.c.

#define do_like_escape   MB_do_like_escape

Definition at line 130 of file like.c.

#define do_like_escape   SB_do_like_escape

Definition at line 130 of file like.c.

#define LIKE_ABORT   (-1)

Definition at line 31 of file like.c.

Referenced by MatchText().

#define LIKE_FALSE   0

Definition at line 30 of file like.c.

Referenced by MatchText().

#define LIKE_TRUE   1
#define MATCH_LOWER (   t)    SB_lower_char((unsigned char) (t), locale, locale_is_c)

Definition at line 135 of file like.c.

#define MatchText   MB_MatchText

Definition at line 145 of file like.c.

#define MatchText   SB_MatchText

Definition at line 145 of file like.c.

#define MatchText   SB_IMatchText

Definition at line 145 of file like.c.

#define MatchText   UTF8_MatchText

Definition at line 145 of file like.c.

#define NextByte (   p,
  plen 
)    ((p)++, (plen)--)

Definition at line 106 of file like.c.

Referenced by MatchText().

#define NextChar (   p,
  plen 
)    do { int __l = pg_mblen(p); (p) +=__l; (plen) -=__l; } while (0)

Definition at line 143 of file like.c.

Referenced by MatchText().

#define NextChar (   p,
  plen 
)    NextByte((p), (plen))

Definition at line 143 of file like.c.

#define NextChar (   p,
  plen 
)    NextByte((p), (plen))

Definition at line 143 of file like.c.

#define NextChar (   p,
  plen 
)    do { (p)++; (plen)--; } while ((plen) > 0 && (*(p) & 0xC0) == 0x80 )

Definition at line 143 of file like.c.

Function Documentation

Datum bytealike ( PG_FUNCTION_ARGS  )

Definition at line 312 of file like.c.

References LIKE_TRUE, PG_GETARG_BYTEA_PP, PG_RETURN_BOOL, result, SB_MatchText(), VARDATA_ANY, and VARSIZE_ANY_EXHDR.

313 {
314  bytea *str = PG_GETARG_BYTEA_PP(0);
315  bytea *pat = PG_GETARG_BYTEA_PP(1);
316  bool result;
317  char *s,
318  *p;
319  int slen,
320  plen;
321 
322  s = VARDATA_ANY(str);
323  slen = VARSIZE_ANY_EXHDR(str);
324  p = VARDATA_ANY(pat);
325  plen = VARSIZE_ANY_EXHDR(pat);
326 
327  result = (SB_MatchText(s, slen, p, plen, 0, true) == LIKE_TRUE);
328 
329  PG_RETURN_BOOL(result);
330 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:347
#define LIKE_TRUE
Definition: like.c:29
return result
Definition: formatting.c:1633
static int SB_MatchText(char *t, int tlen, char *p, int plen, pg_locale_t locale, bool locale_is_c)
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_BYTEA_PP(n)
Definition: fmgr.h:272
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:340
Definition: c.h:439
Datum byteanlike ( PG_FUNCTION_ARGS  )

Definition at line 333 of file like.c.

References LIKE_TRUE, PG_GETARG_BYTEA_PP, PG_RETURN_BOOL, result, SB_MatchText(), VARDATA_ANY, and VARSIZE_ANY_EXHDR.

334 {
335  bytea *str = PG_GETARG_BYTEA_PP(0);
336  bytea *pat = PG_GETARG_BYTEA_PP(1);
337  bool result;
338  char *s,
339  *p;
340  int slen,
341  plen;
342 
343  s = VARDATA_ANY(str);
344  slen = VARSIZE_ANY_EXHDR(str);
345  p = VARDATA_ANY(pat);
346  plen = VARSIZE_ANY_EXHDR(pat);
347 
348  result = (SB_MatchText(s, slen, p, plen, 0, true) != LIKE_TRUE);
349 
350  PG_RETURN_BOOL(result);
351 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:347
#define LIKE_TRUE
Definition: like.c:29
return result
Definition: formatting.c:1633
static int SB_MatchText(char *t, int tlen, char *p, int plen, pg_locale_t locale, bool locale_is_c)
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_BYTEA_PP(n)
Definition: fmgr.h:272
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:340
Definition: c.h:439
static int Generic_Text_IC_like ( text str,
text pat,
Oid  collation 
)
inlinestatic

Definition at line 162 of file like.c.

References COLLPROVIDER_ICU, DatumGetTextPP, DEFAULT_COLLATION_OID, DirectFunctionCall1Coll(), ereport, errcode(), errhint(), errmsg(), ERROR, GetDatabaseEncoding(), lc_ctype_is_c(), locale, lower(), MB_MatchText(), OidIsValid, pg_database_encoding_max_length(), pg_newlocale_from_collation(), PG_UTF8, PointerGetDatum, pg_locale_struct::provider, SB_IMatchText(), UTF8_MatchText(), VARDATA_ANY, and VARSIZE_ANY_EXHDR.

Referenced by nameiclike(), nameicnlike(), texticlike(), and texticnlike().

163 {
164  char *s,
165  *p;
166  int slen,
167  plen;
168  pg_locale_t locale = 0;
169  bool locale_is_c = false;
170 
171  if (lc_ctype_is_c(collation))
172  locale_is_c = true;
173  else if (collation != DEFAULT_COLLATION_OID)
174  {
175  if (!OidIsValid(collation))
176  {
177  /*
178  * This typically means that the parser could not resolve a
179  * conflict of implicit collations, so report it that way.
180  */
181  ereport(ERROR,
182  (errcode(ERRCODE_INDETERMINATE_COLLATION),
183  errmsg("could not determine which collation to use for ILIKE"),
184  errhint("Use the COLLATE clause to set the collation explicitly.")));
185  }
186  locale = pg_newlocale_from_collation(collation);
187  }
188 
189  /*
190  * For efficiency reasons, in the single byte case we don't call lower()
191  * on the pattern and text, but instead call SB_lower_char on each
192  * character. In the multi-byte case we don't have much choice :-(. Also,
193  * ICU does not support single-character case folding, so we go the long
194  * way.
195  */
196 
197  if (pg_database_encoding_max_length() > 1 || (locale && locale->provider == COLLPROVIDER_ICU))
198  {
199  /* lower's result is never packed, so OK to use old macros here */
201  PointerGetDatum(pat)));
202  p = VARDATA_ANY(pat);
203  plen = VARSIZE_ANY_EXHDR(pat);
205  PointerGetDatum(str)));
206  s = VARDATA_ANY(str);
207  slen = VARSIZE_ANY_EXHDR(str);
208  if (GetDatabaseEncoding() == PG_UTF8)
209  return UTF8_MatchText(s, slen, p, plen, 0, true);
210  else
211  return MB_MatchText(s, slen, p, plen, 0, true);
212  }
213  else
214  {
215  p = VARDATA_ANY(pat);
216  plen = VARSIZE_ANY_EXHDR(pat);
217  s = VARDATA_ANY(str);
218  slen = VARSIZE_ANY_EXHDR(str);
219  return SB_IMatchText(s, slen, p, plen, locale, locale_is_c);
220  }
221 }
#define COLLPROVIDER_ICU
Definition: pg_collation.h:85
int errhint(const char *fmt,...)
Definition: elog.c:987
#define VARDATA_ANY(PTR)
Definition: postgres.h:347
Datum lower(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:43
#define PointerGetDatum(X)
Definition: postgres.h:562
#define DatumGetTextPP(X)
Definition: fmgr.h:256
int errcode(int sqlerrcode)
Definition: elog.c:575
#define OidIsValid(objectId)
Definition: c.h:538
static int UTF8_MatchText(char *t, int tlen, char *p, int plen, pg_locale_t locale, bool locale_is_c)
#define ERROR
Definition: elog.h:43
static int MB_MatchText(char *t, int tlen, char *p, int plen, pg_locale_t locale, bool locale_is_c)
#define DEFAULT_COLLATION_OID
Definition: pg_collation.h:75
int pg_database_encoding_max_length(void)
Definition: wchar.c:1833
Datum DirectFunctionCall1Coll(PGFunction func, Oid collation, Datum arg1)
Definition: fmgr.c:707
#define ereport(elevel, rest)
Definition: elog.h:122
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition: pg_locale.c:1275
int GetDatabaseEncoding(void)
Definition: mbutils.c:1015
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:340
int errmsg(const char *fmt,...)
Definition: elog.c:797
static char * locale
Definition: initdb.c:123
static int SB_IMatchText(char *t, int tlen, char *p, int plen, pg_locale_t locale, bool locale_is_c)
bool lc_ctype_is_c(Oid collation)
Definition: pg_locale.c:1178
static int GenericMatchText ( char *  s,
int  slen,
char *  p,
int  plen 
)
inlinestatic

Definition at line 151 of file like.c.

References GetDatabaseEncoding(), MB_MatchText(), pg_database_encoding_max_length(), PG_UTF8, SB_MatchText(), and UTF8_MatchText().

Referenced by namelike(), namenlike(), textlike(), and textnlike().

152 {
154  return SB_MatchText(s, slen, p, plen, 0, true);
155  else if (GetDatabaseEncoding() == PG_UTF8)
156  return UTF8_MatchText(s, slen, p, plen, 0, true);
157  else
158  return MB_MatchText(s, slen, p, plen, 0, true);
159 }
static int SB_MatchText(char *t, int tlen, char *p, int plen, pg_locale_t locale, bool locale_is_c)
static int UTF8_MatchText(char *t, int tlen, char *p, int plen, pg_locale_t locale, bool locale_is_c)
static int MB_MatchText(char *t, int tlen, char *p, int plen, pg_locale_t locale, bool locale_is_c)
int pg_database_encoding_max_length(void)
Definition: wchar.c:1833
int GetDatabaseEncoding(void)
Definition: mbutils.c:1015
Datum like_escape ( PG_FUNCTION_ARGS  )

Definition at line 416 of file like.c.

References MB_do_like_escape(), pg_database_encoding_max_length(), PG_GETARG_TEXT_PP, PG_RETURN_TEXT_P, result, and SB_do_like_escape().

417 {
418  text *pat = PG_GETARG_TEXT_PP(0);
419  text *esc = PG_GETARG_TEXT_PP(1);
420  text *result;
421 
423  result = SB_do_like_escape(pat, esc);
424  else
425  result = MB_do_like_escape(pat, esc);
426 
427  PG_RETURN_TEXT_P(result);
428 }
static text * SB_do_like_escape(text *, text *)
return result
Definition: formatting.c:1633
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
int pg_database_encoding_max_length(void)
Definition: wchar.c:1833
static text * MB_do_like_escape(text *, text *)
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:330
Definition: c.h:439
Datum like_escape_bytea ( PG_FUNCTION_ARGS  )

Definition at line 435 of file like.c.

References PG_GETARG_BYTEA_PP, PG_RETURN_BYTEA_P, result, and SB_do_like_escape().

436 {
437  bytea *pat = PG_GETARG_BYTEA_PP(0);
438  bytea *esc = PG_GETARG_BYTEA_PP(1);
439  bytea *result = SB_do_like_escape((text *) pat, (text *) esc);
440 
441  PG_RETURN_BYTEA_P((bytea *) result);
442 }
static text * SB_do_like_escape(text *, text *)
return result
Definition: formatting.c:1633
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:329
#define PG_GETARG_BYTEA_PP(n)
Definition: fmgr.h:272
Definition: c.h:439
static text* MB_do_like_escape ( text ,
text  
)
static

Referenced by like_escape().

static int MB_MatchText ( char *  t,
int  tlen,
char *  p,
int  plen,
pg_locale_t  locale,
bool  locale_is_c 
)
static
Datum nameiclike ( PG_FUNCTION_ARGS  )

Definition at line 358 of file like.c.

References DatumGetTextPP, DirectFunctionCall1, Generic_Text_IC_like(), LIKE_TRUE, name_text(), NameGetDatum, PG_GET_COLLATION, PG_GETARG_NAME, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and result.

359 {
360  Name str = PG_GETARG_NAME(0);
361  text *pat = PG_GETARG_TEXT_PP(1);
362  bool result;
363  text *strtext;
364 
366  NameGetDatum(str)));
367  result = (Generic_Text_IC_like(strtext, pat, PG_GET_COLLATION()) == LIKE_TRUE);
368 
369  PG_RETURN_BOOL(result);
370 }
#define NameGetDatum(X)
Definition: postgres.h:601
#define DatumGetTextPP(X)
Definition: fmgr.h:256
#define LIKE_TRUE
Definition: like.c:29
return result
Definition: formatting.c:1633
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
#define PG_GET_COLLATION()
Definition: fmgr.h:163
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
Definition: c.h:493
Datum name_text(PG_FUNCTION_ARGS)
Definition: varlena.c:3185
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static int Generic_Text_IC_like(text *str, text *pat, Oid collation)
Definition: like.c:162
Definition: c.h:439
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243
Datum nameicnlike ( PG_FUNCTION_ARGS  )

Definition at line 373 of file like.c.

References DatumGetTextPP, DirectFunctionCall1, Generic_Text_IC_like(), LIKE_TRUE, name_text(), NameGetDatum, PG_GET_COLLATION, PG_GETARG_NAME, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and result.

374 {
375  Name str = PG_GETARG_NAME(0);
376  text *pat = PG_GETARG_TEXT_PP(1);
377  bool result;
378  text *strtext;
379 
381  NameGetDatum(str)));
382  result = (Generic_Text_IC_like(strtext, pat, PG_GET_COLLATION()) != LIKE_TRUE);
383 
384  PG_RETURN_BOOL(result);
385 }
#define NameGetDatum(X)
Definition: postgres.h:601
#define DatumGetTextPP(X)
Definition: fmgr.h:256
#define LIKE_TRUE
Definition: like.c:29
return result
Definition: formatting.c:1633
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
#define PG_GET_COLLATION()
Definition: fmgr.h:163
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
Definition: c.h:493
Datum name_text(PG_FUNCTION_ARGS)
Definition: varlena.c:3185
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static int Generic_Text_IC_like(text *str, text *pat, Oid collation)
Definition: like.c:162
Definition: c.h:439
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243
Datum namelike ( PG_FUNCTION_ARGS  )

Definition at line 228 of file like.c.

References GenericMatchText(), LIKE_TRUE, NameStr, PG_GETARG_NAME, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, result, VARDATA_ANY, and VARSIZE_ANY_EXHDR.

229 {
230  Name str = PG_GETARG_NAME(0);
231  text *pat = PG_GETARG_TEXT_PP(1);
232  bool result;
233  char *s,
234  *p;
235  int slen,
236  plen;
237 
238  s = NameStr(*str);
239  slen = strlen(s);
240  p = VARDATA_ANY(pat);
241  plen = VARSIZE_ANY_EXHDR(pat);
242 
243  result = (GenericMatchText(s, slen, p, plen) == LIKE_TRUE);
244 
245  PG_RETURN_BOOL(result);
246 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:347
#define LIKE_TRUE
Definition: like.c:29
return result
Definition: formatting.c:1633
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
static int GenericMatchText(char *s, int slen, char *p, int plen)
Definition: like.c:151
Definition: c.h:493
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:340
#define NameStr(name)
Definition: c.h:499
Definition: c.h:439
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243
Datum namenlike ( PG_FUNCTION_ARGS  )

Definition at line 249 of file like.c.

References GenericMatchText(), LIKE_TRUE, NameStr, PG_GETARG_NAME, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, result, VARDATA_ANY, and VARSIZE_ANY_EXHDR.

250 {
251  Name str = PG_GETARG_NAME(0);
252  text *pat = PG_GETARG_TEXT_PP(1);
253  bool result;
254  char *s,
255  *p;
256  int slen,
257  plen;
258 
259  s = NameStr(*str);
260  slen = strlen(s);
261  p = VARDATA_ANY(pat);
262  plen = VARSIZE_ANY_EXHDR(pat);
263 
264  result = (GenericMatchText(s, slen, p, plen) != LIKE_TRUE);
265 
266  PG_RETURN_BOOL(result);
267 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:347
#define LIKE_TRUE
Definition: like.c:29
return result
Definition: formatting.c:1633
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
static int GenericMatchText(char *s, int slen, char *p, int plen)
Definition: like.c:151
Definition: c.h:493
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:340
#define NameStr(name)
Definition: c.h:499
Definition: c.h:439
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243
static text* SB_do_like_escape ( text ,
text  
)
static

Referenced by like_escape(), and like_escape_bytea().

static int SB_IMatchText ( char *  t,
int  tlen,
char *  p,
int  plen,
pg_locale_t  locale,
bool  locale_is_c 
)
static

Referenced by Generic_Text_IC_like().

static char SB_lower_char ( unsigned char  c,
pg_locale_t  locale,
bool  locale_is_c 
)
static

Definition at line 93 of file like.c.

References pg_locale_struct::info, pg_ascii_tolower(), pg_tolower(), and tolower_l.

94 {
95  if (locale_is_c)
96  return pg_ascii_tolower(c);
97 #ifdef HAVE_LOCALE_T
98  else if (locale)
99  return tolower_l(c, locale->info.lt);
100 #endif
101  else
102  return pg_tolower(c);
103 }
unsigned char pg_ascii_tolower(unsigned char ch)
Definition: pgstrcasecmp.c:146
union pg_locale_struct::@120 info
unsigned char pg_tolower(unsigned char ch)
Definition: pgstrcasecmp.c:122
char * c
#define tolower_l
Definition: win32.h:324
static int SB_MatchText ( char *  t,
int  tlen,
char *  p,
int  plen,
pg_locale_t  locale,
bool  locale_is_c 
)
static
Datum texticlike ( PG_FUNCTION_ARGS  )

Definition at line 388 of file like.c.

References Generic_Text_IC_like(), LIKE_TRUE, PG_GET_COLLATION, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and result.

389 {
390  text *str = PG_GETARG_TEXT_PP(0);
391  text *pat = PG_GETARG_TEXT_PP(1);
392  bool result;
393 
394  result = (Generic_Text_IC_like(str, pat, PG_GET_COLLATION()) == LIKE_TRUE);
395 
396  PG_RETURN_BOOL(result);
397 }
#define LIKE_TRUE
Definition: like.c:29
return result
Definition: formatting.c:1633
#define PG_GET_COLLATION()
Definition: fmgr.h:163
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static int Generic_Text_IC_like(text *str, text *pat, Oid collation)
Definition: like.c:162
Definition: c.h:439
Datum texticnlike ( PG_FUNCTION_ARGS  )

Definition at line 400 of file like.c.

References Generic_Text_IC_like(), LIKE_TRUE, PG_GET_COLLATION, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and result.

401 {
402  text *str = PG_GETARG_TEXT_PP(0);
403  text *pat = PG_GETARG_TEXT_PP(1);
404  bool result;
405 
406  result = (Generic_Text_IC_like(str, pat, PG_GET_COLLATION()) != LIKE_TRUE);
407 
408  PG_RETURN_BOOL(result);
409 }
#define LIKE_TRUE
Definition: like.c:29
return result
Definition: formatting.c:1633
#define PG_GET_COLLATION()
Definition: fmgr.h:163
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static int Generic_Text_IC_like(text *str, text *pat, Oid collation)
Definition: like.c:162
Definition: c.h:439
Datum textlike ( PG_FUNCTION_ARGS  )

Definition at line 270 of file like.c.

References GenericMatchText(), LIKE_TRUE, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, result, VARDATA_ANY, and VARSIZE_ANY_EXHDR.

271 {
272  text *str = PG_GETARG_TEXT_PP(0);
273  text *pat = PG_GETARG_TEXT_PP(1);
274  bool result;
275  char *s,
276  *p;
277  int slen,
278  plen;
279 
280  s = VARDATA_ANY(str);
281  slen = VARSIZE_ANY_EXHDR(str);
282  p = VARDATA_ANY(pat);
283  plen = VARSIZE_ANY_EXHDR(pat);
284 
285  result = (GenericMatchText(s, slen, p, plen) == LIKE_TRUE);
286 
287  PG_RETURN_BOOL(result);
288 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:347
#define LIKE_TRUE
Definition: like.c:29
return result
Definition: formatting.c:1633
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
static int GenericMatchText(char *s, int slen, char *p, int plen)
Definition: like.c:151
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:340
Definition: c.h:439
Datum textnlike ( PG_FUNCTION_ARGS  )

Definition at line 291 of file like.c.

References GenericMatchText(), LIKE_TRUE, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, result, VARDATA_ANY, and VARSIZE_ANY_EXHDR.

292 {
293  text *str = PG_GETARG_TEXT_PP(0);
294  text *pat = PG_GETARG_TEXT_PP(1);
295  bool result;
296  char *s,
297  *p;
298  int slen,
299  plen;
300 
301  s = VARDATA_ANY(str);
302  slen = VARSIZE_ANY_EXHDR(str);
303  p = VARDATA_ANY(pat);
304  plen = VARSIZE_ANY_EXHDR(pat);
305 
306  result = (GenericMatchText(s, slen, p, plen) != LIKE_TRUE);
307 
308  PG_RETURN_BOOL(result);
309 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:347
#define LIKE_TRUE
Definition: like.c:29
return result
Definition: formatting.c:1633
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
static int GenericMatchText(char *s, int slen, char *p, int plen)
Definition: like.c:151
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:340
Definition: c.h:439
static int UTF8_MatchText ( char *  t,
int  tlen,
char *  p,
int  plen,
pg_locale_t  locale,
bool  locale_is_c 
)
static
static int wchareq ( char *  p1,
char *  p2 
)
inlinestatic

Definition at line 57 of file like.c.

References pg_mblen().

58 {
59  int p1_len;
60 
61  /* Optimization: quickly compare the first byte. */
62  if (*p1 != *p2)
63  return 0;
64 
65  p1_len = pg_mblen(p1);
66  if (pg_mblen(p2) != p1_len)
67  return 0;
68 
69  /* They are the same length */
70  while (p1_len--)
71  {
72  if (*p1++ != *p2++)
73  return 0;
74  }
75  return 1;
76 }
int pg_mblen(const char *mbstr)
Definition: mbutils.c:771