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 315 of file like.c.

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

316 {
317  bytea *str = PG_GETARG_BYTEA_PP(0);
318  bytea *pat = PG_GETARG_BYTEA_PP(1);
319  bool result;
320  char *s,
321  *p;
322  int slen,
323  plen;
324 
325  s = VARDATA_ANY(str);
326  slen = VARSIZE_ANY_EXHDR(str);
327  p = VARDATA_ANY(pat);
328  plen = VARSIZE_ANY_EXHDR(pat);
329 
330  result = (SB_MatchText(s, slen, p, plen, 0, true) == LIKE_TRUE);
331 
332  PG_RETURN_BOOL(result);
333 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:349
#define LIKE_TRUE
Definition: like.c:29
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:303
#define PG_GETARG_BYTEA_PP(n)
Definition: fmgr.h:268
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:342
Definition: c.h:435
Datum byteanlike ( PG_FUNCTION_ARGS  )

Definition at line 336 of file like.c.

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

337 {
338  bytea *str = PG_GETARG_BYTEA_PP(0);
339  bytea *pat = PG_GETARG_BYTEA_PP(1);
340  bool result;
341  char *s,
342  *p;
343  int slen,
344  plen;
345 
346  s = VARDATA_ANY(str);
347  slen = VARSIZE_ANY_EXHDR(str);
348  p = VARDATA_ANY(pat);
349  plen = VARSIZE_ANY_EXHDR(pat);
350 
351  result = (SB_MatchText(s, slen, p, plen, 0, true) != LIKE_TRUE);
352 
353  PG_RETURN_BOOL(result);
354 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:349
#define LIKE_TRUE
Definition: like.c:29
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:303
#define PG_GETARG_BYTEA_PP(n)
Definition: fmgr.h:268
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:342
Definition: c.h:435
static int Generic_Text_IC_like ( text str,
text pat,
Oid  collation 
)
inlinestatic

Definition at line 162 of file like.c.

References DatumGetTextP, 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, SB_IMatchText(), UTF8_MatchText(), VARDATA, VARDATA_ANY, VARHDRSZ, VARSIZE, and VARSIZE_ANY_EXHDR.

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

163 {
164  char *s,
165  *p;
166  int slen,
167  plen;
168 
169  /*
170  * For efficiency reasons, in the single byte case we don't call lower()
171  * on the pattern and text, but instead call SB_lower_char on each
172  * character. In the multi-byte case we don't have much choice :-(
173  */
174 
176  {
177  /* lower's result is never packed, so OK to use old macros here */
179  PointerGetDatum(pat)));
180  p = VARDATA(pat);
181  plen = (VARSIZE(pat) - VARHDRSZ);
183  PointerGetDatum(str)));
184  s = VARDATA(str);
185  slen = (VARSIZE(str) - VARHDRSZ);
186  if (GetDatabaseEncoding() == PG_UTF8)
187  return UTF8_MatchText(s, slen, p, plen, 0, true);
188  else
189  return MB_MatchText(s, slen, p, plen, 0, true);
190  }
191  else
192  {
193  /*
194  * Here we need to prepare locale information for SB_lower_char. This
195  * should match the methods used in str_tolower().
196  */
197  pg_locale_t locale = 0;
198  bool locale_is_c = false;
199 
200  if (lc_ctype_is_c(collation))
201  locale_is_c = true;
202  else if (collation != DEFAULT_COLLATION_OID)
203  {
204  if (!OidIsValid(collation))
205  {
206  /*
207  * This typically means that the parser could not resolve a
208  * conflict of implicit collations, so report it that way.
209  */
210  ereport(ERROR,
211  (errcode(ERRCODE_INDETERMINATE_COLLATION),
212  errmsg("could not determine which collation to use for ILIKE"),
213  errhint("Use the COLLATE clause to set the collation explicitly.")));
214  }
215  locale = pg_newlocale_from_collation(collation);
216  }
217 
218  p = VARDATA_ANY(pat);
219  plen = VARSIZE_ANY_EXHDR(pat);
220  s = VARDATA_ANY(str);
221  slen = VARSIZE_ANY_EXHDR(str);
222  return SB_IMatchText(s, slen, p, plen, locale, locale_is_c);
223  }
224 }
int errhint(const char *fmt,...)
Definition: elog.c:987
#define VARDATA_ANY(PTR)
Definition: postgres.h:349
#define VARDATA(PTR)
Definition: postgres.h:305
Datum lower(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:43
#define VARSIZE(PTR)
Definition: postgres.h:306
#define PointerGetDatum(X)
Definition: postgres.h:564
#define VARHDRSZ
Definition: c.h:441
int errcode(int sqlerrcode)
Definition: elog.c:575
#define OidIsValid(objectId)
Definition: c.h:534
int pg_locale_t
Definition: pg_locale.h:71
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:68
int pg_database_encoding_max_length(void)
Definition: wchar.c:1833
Datum DirectFunctionCall1Coll(PGFunction func, Oid collation, Datum arg1)
Definition: fmgr.c:1016
#define ereport(elevel, rest)
Definition: elog.h:122
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition: pg_locale.c:1260
int GetDatabaseEncoding(void)
Definition: mbutils.c:1015
#define DatumGetTextP(X)
Definition: fmgr.h:248
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:342
int errmsg(const char *fmt,...)
Definition: elog.c:797
static char * locale
Definition: initdb.c:122
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:1173
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 419 of file like.c.

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

420 {
421  text *pat = PG_GETARG_TEXT_PP(0);
422  text *esc = PG_GETARG_TEXT_PP(1);
423  text *result;
424 
426  result = SB_do_like_escape(pat, esc);
427  else
428  result = MB_do_like_escape(pat, esc);
429 
430  PG_RETURN_TEXT_P(result);
431 }
static text * SB_do_like_escape(text *, text *)
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:270
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:314
Definition: c.h:435
Datum like_escape_bytea ( PG_FUNCTION_ARGS  )

Definition at line 438 of file like.c.

References PG_GETARG_BYTEA_PP, PG_RETURN_BYTEA_P, and SB_do_like_escape().

439 {
440  bytea *pat = PG_GETARG_BYTEA_PP(0);
441  bytea *esc = PG_GETARG_BYTEA_PP(1);
442  bytea *result = SB_do_like_escape((text *) pat, (text *) esc);
443 
444  PG_RETURN_BYTEA_P((bytea *) result);
445 }
static text * SB_do_like_escape(text *, text *)
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:313
#define PG_GETARG_BYTEA_PP(n)
Definition: fmgr.h:268
Definition: c.h:435
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 361 of file like.c.

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

362 {
363  Name str = PG_GETARG_NAME(0);
364  text *pat = PG_GETARG_TEXT_PP(1);
365  bool result;
366  text *strtext;
367 
369  NameGetDatum(str)));
370  result = (Generic_Text_IC_like(strtext, pat, PG_GET_COLLATION()) == LIKE_TRUE);
371 
372  PG_RETURN_BOOL(result);
373 }
#define NameGetDatum(X)
Definition: postgres.h:603
#define LIKE_TRUE
Definition: like.c:29
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:555
#define PG_GET_COLLATION()
Definition: fmgr.h:155
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:270
Definition: c.h:489
Datum name_text(PG_FUNCTION_ARGS)
Definition: varlena.c:3054
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
static int Generic_Text_IC_like(text *str, text *pat, Oid collation)
Definition: like.c:162
#define DatumGetTextP(X)
Definition: fmgr.h:248
Definition: c.h:435
#define PG_GETARG_NAME(n)
Definition: fmgr.h:234
Datum nameicnlike ( PG_FUNCTION_ARGS  )

Definition at line 376 of file like.c.

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

377 {
378  Name str = PG_GETARG_NAME(0);
379  text *pat = PG_GETARG_TEXT_PP(1);
380  bool result;
381  text *strtext;
382 
384  NameGetDatum(str)));
385  result = (Generic_Text_IC_like(strtext, pat, PG_GET_COLLATION()) != LIKE_TRUE);
386 
387  PG_RETURN_BOOL(result);
388 }
#define NameGetDatum(X)
Definition: postgres.h:603
#define LIKE_TRUE
Definition: like.c:29
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:555
#define PG_GET_COLLATION()
Definition: fmgr.h:155
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:270
Definition: c.h:489
Datum name_text(PG_FUNCTION_ARGS)
Definition: varlena.c:3054
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
static int Generic_Text_IC_like(text *str, text *pat, Oid collation)
Definition: like.c:162
#define DatumGetTextP(X)
Definition: fmgr.h:248
Definition: c.h:435
#define PG_GETARG_NAME(n)
Definition: fmgr.h:234
Datum namelike ( PG_FUNCTION_ARGS  )

Definition at line 231 of file like.c.

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

232 {
233  Name str = PG_GETARG_NAME(0);
234  text *pat = PG_GETARG_TEXT_PP(1);
235  bool result;
236  char *s,
237  *p;
238  int slen,
239  plen;
240 
241  s = NameStr(*str);
242  slen = strlen(s);
243  p = VARDATA_ANY(pat);
244  plen = VARSIZE_ANY_EXHDR(pat);
245 
246  result = (GenericMatchText(s, slen, p, plen) == LIKE_TRUE);
247 
248  PG_RETURN_BOOL(result);
249 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:349
#define LIKE_TRUE
Definition: like.c:29
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:270
static int GenericMatchText(char *s, int slen, char *p, int plen)
Definition: like.c:151
Definition: c.h:489
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:342
#define NameStr(name)
Definition: c.h:495
Definition: c.h:435
#define PG_GETARG_NAME(n)
Definition: fmgr.h:234
Datum namenlike ( PG_FUNCTION_ARGS  )

Definition at line 252 of file like.c.

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

253 {
254  Name str = PG_GETARG_NAME(0);
255  text *pat = PG_GETARG_TEXT_PP(1);
256  bool result;
257  char *s,
258  *p;
259  int slen,
260  plen;
261 
262  s = NameStr(*str);
263  slen = strlen(s);
264  p = VARDATA_ANY(pat);
265  plen = VARSIZE_ANY_EXHDR(pat);
266 
267  result = (GenericMatchText(s, slen, p, plen) != LIKE_TRUE);
268 
269  PG_RETURN_BOOL(result);
270 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:349
#define LIKE_TRUE
Definition: like.c:29
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:270
static int GenericMatchText(char *s, int slen, char *p, int plen)
Definition: like.c:151
Definition: c.h:489
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:342
#define NameStr(name)
Definition: c.h:495
Definition: c.h:435
#define PG_GETARG_NAME(n)
Definition: fmgr.h:234
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_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);
100 #endif
101  else
102  return pg_tolower(c);
103 }
unsigned char pg_ascii_tolower(unsigned char ch)
Definition: pgstrcasecmp.c:146
unsigned char pg_tolower(unsigned char ch)
Definition: pgstrcasecmp.c:122
char * c
#define tolower_l
Definition: win32.h:334
static char * locale
Definition: initdb.c:122
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 391 of file like.c.

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

392 {
393  text *str = PG_GETARG_TEXT_PP(0);
394  text *pat = PG_GETARG_TEXT_PP(1);
395  bool result;
396 
397  result = (Generic_Text_IC_like(str, pat, PG_GET_COLLATION()) == LIKE_TRUE);
398 
399  PG_RETURN_BOOL(result);
400 }
#define LIKE_TRUE
Definition: like.c:29
#define PG_GET_COLLATION()
Definition: fmgr.h:155
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:270
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
static int Generic_Text_IC_like(text *str, text *pat, Oid collation)
Definition: like.c:162
Definition: c.h:435
Datum texticnlike ( PG_FUNCTION_ARGS  )

Definition at line 403 of file like.c.

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

404 {
405  text *str = PG_GETARG_TEXT_PP(0);
406  text *pat = PG_GETARG_TEXT_PP(1);
407  bool result;
408 
409  result = (Generic_Text_IC_like(str, pat, PG_GET_COLLATION()) != LIKE_TRUE);
410 
411  PG_RETURN_BOOL(result);
412 }
#define LIKE_TRUE
Definition: like.c:29
#define PG_GET_COLLATION()
Definition: fmgr.h:155
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:270
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
static int Generic_Text_IC_like(text *str, text *pat, Oid collation)
Definition: like.c:162
Definition: c.h:435
Datum textlike ( PG_FUNCTION_ARGS  )

Definition at line 273 of file like.c.

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

274 {
275  text *str = PG_GETARG_TEXT_PP(0);
276  text *pat = PG_GETARG_TEXT_PP(1);
277  bool result;
278  char *s,
279  *p;
280  int slen,
281  plen;
282 
283  s = VARDATA_ANY(str);
284  slen = VARSIZE_ANY_EXHDR(str);
285  p = VARDATA_ANY(pat);
286  plen = VARSIZE_ANY_EXHDR(pat);
287 
288  result = (GenericMatchText(s, slen, p, plen) == LIKE_TRUE);
289 
290  PG_RETURN_BOOL(result);
291 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:349
#define LIKE_TRUE
Definition: like.c:29
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:270
static int GenericMatchText(char *s, int slen, char *p, int plen)
Definition: like.c:151
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:342
Definition: c.h:435
Datum textnlike ( PG_FUNCTION_ARGS  )

Definition at line 294 of file like.c.

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

295 {
296  text *str = PG_GETARG_TEXT_PP(0);
297  text *pat = PG_GETARG_TEXT_PP(1);
298  bool result;
299  char *s,
300  *p;
301  int slen,
302  plen;
303 
304  s = VARDATA_ANY(str);
305  slen = VARSIZE_ANY_EXHDR(str);
306  p = VARDATA_ANY(pat);
307  plen = VARSIZE_ANY_EXHDR(pat);
308 
309  result = (GenericMatchText(s, slen, p, plen) != LIKE_TRUE);
310 
311  PG_RETURN_BOOL(result);
312 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:349
#define LIKE_TRUE
Definition: like.c:29
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:270
static int GenericMatchText(char *s, int slen, char *p, int plen)
Definition: like.c:151
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:342
Definition: c.h:435
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