PostgreSQL Source Code  git master
citext.c File Reference
#include "postgres.h"
#include "catalog/pg_collation.h"
#include "utils/builtins.h"
#include "utils/formatting.h"
#include "utils/hashutils.h"
#include "utils/varlena.h"
Include dependency graph for citext.c:

Go to the source code of this file.

Functions

static int32 citextcmp (text *left, text *right, Oid collid)
 
static int32 internal_citext_pattern_cmp (text *left, text *right, Oid collid)
 
 PG_FUNCTION_INFO_V1 (citext_cmp)
 
Datum citext_cmp (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (citext_pattern_cmp)
 
Datum citext_pattern_cmp (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (citext_hash)
 
Datum citext_hash (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (citext_hash_extended)
 
Datum citext_hash_extended (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (citext_eq)
 
Datum citext_eq (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (citext_ne)
 
Datum citext_ne (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (citext_lt)
 
Datum citext_lt (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (citext_le)
 
Datum citext_le (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (citext_gt)
 
Datum citext_gt (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (citext_ge)
 
Datum citext_ge (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (citext_pattern_lt)
 
Datum citext_pattern_lt (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (citext_pattern_le)
 
Datum citext_pattern_le (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (citext_pattern_gt)
 
Datum citext_pattern_gt (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (citext_pattern_ge)
 
Datum citext_pattern_ge (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (citext_smaller)
 
Datum citext_smaller (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (citext_larger)
 
Datum citext_larger (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 

Function Documentation

◆ citext_cmp()

Datum citext_cmp ( PG_FUNCTION_ARGS  )

Definition at line 106 of file citext.c.

References citext_pattern_cmp(), citextcmp(), PG_FREE_IF_COPY, PG_FUNCTION_INFO_V1(), PG_GET_COLLATION, PG_GETARG_TEXT_PP, and PG_RETURN_INT32.

Referenced by internal_citext_pattern_cmp().

107 {
108  text *left = PG_GETARG_TEXT_PP(0);
109  text *right = PG_GETARG_TEXT_PP(1);
110  int32 result;
111 
112  result = citextcmp(left, right, PG_GET_COLLATION());
113 
114  PG_FREE_IF_COPY(left, 0);
115  PG_FREE_IF_COPY(right, 1);
116 
117  PG_RETURN_INT32(result);
118 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
static int32 citextcmp(text *left, text *right, Oid collid)
Definition: citext.c:35
#define PG_GET_COLLATION()
Definition: fmgr.h:193
signed int int32
Definition: c.h:346
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
Definition: c.h:549

◆ citext_eq()

Datum citext_eq ( PG_FUNCTION_ARGS  )

Definition at line 185 of file citext.c.

References citext_ne(), pfree(), PG_FREE_IF_COPY, PG_FUNCTION_INFO_V1(), PG_GETARG_TEXT_PP, PG_RETURN_BOOL, str_tolower(), VARDATA_ANY, and VARSIZE_ANY_EXHDR.

Referenced by citext_hash_extended().

186 {
187  text *left = PG_GETARG_TEXT_PP(0);
188  text *right = PG_GETARG_TEXT_PP(1);
189  char *lcstr,
190  *rcstr;
191  bool result;
192 
193  /* We can't compare lengths in advance of downcasing ... */
194 
195  lcstr = str_tolower(VARDATA_ANY(left), VARSIZE_ANY_EXHDR(left), DEFAULT_COLLATION_OID);
196  rcstr = str_tolower(VARDATA_ANY(right), VARSIZE_ANY_EXHDR(right), DEFAULT_COLLATION_OID);
197 
198  /*
199  * Since we only care about equality or not-equality, we can avoid all the
200  * expense of strcoll() here, and just do bitwise comparison.
201  */
202  result = (strcmp(lcstr, rcstr) == 0);
203 
204  pfree(lcstr);
205  pfree(rcstr);
206  PG_FREE_IF_COPY(left, 0);
207  PG_FREE_IF_COPY(right, 1);
208 
209  PG_RETURN_BOOL(result);
210 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:348
char * str_tolower(const char *buff, size_t nbytes, Oid collid)
Definition: formatting.c:1645
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
void pfree(void *pointer)
Definition: mcxt.c:1056
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
Definition: c.h:549

◆ citext_ge()

Datum citext_ge ( PG_FUNCTION_ARGS  )

Definition at line 296 of file citext.c.

References citext_pattern_lt(), citextcmp(), PG_FREE_IF_COPY, PG_FUNCTION_INFO_V1(), PG_GET_COLLATION, PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

Referenced by citext_gt().

297 {
298  text *left = PG_GETARG_TEXT_PP(0);
299  text *right = PG_GETARG_TEXT_PP(1);
300  bool result;
301 
302  result = citextcmp(left, right, PG_GET_COLLATION()) >= 0;
303 
304  PG_FREE_IF_COPY(left, 0);
305  PG_FREE_IF_COPY(right, 1);
306 
307  PG_RETURN_BOOL(result);
308 }
static int32 citextcmp(text *left, text *right, Oid collid)
Definition: citext.c:35
#define PG_GET_COLLATION()
Definition: fmgr.h:193
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
Definition: c.h:549

◆ citext_gt()

Datum citext_gt ( PG_FUNCTION_ARGS  )

Definition at line 279 of file citext.c.

References citext_ge(), citextcmp(), PG_FREE_IF_COPY, PG_FUNCTION_INFO_V1(), PG_GET_COLLATION, PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

Referenced by citext_le().

280 {
281  text *left = PG_GETARG_TEXT_PP(0);
282  text *right = PG_GETARG_TEXT_PP(1);
283  bool result;
284 
285  result = citextcmp(left, right, PG_GET_COLLATION()) > 0;
286 
287  PG_FREE_IF_COPY(left, 0);
288  PG_FREE_IF_COPY(right, 1);
289 
290  PG_RETURN_BOOL(result);
291 }
static int32 citextcmp(text *left, text *right, Oid collid)
Definition: citext.c:35
#define PG_GET_COLLATION()
Definition: fmgr.h:193
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
Definition: c.h:549

◆ citext_hash()

Datum citext_hash ( PG_FUNCTION_ARGS  )

Definition at line 140 of file citext.c.

References citext_hash_extended(), hash_any(), pfree(), PG_FREE_IF_COPY, PG_FUNCTION_INFO_V1(), PG_GETARG_TEXT_PP, PG_RETURN_DATUM, generate_unaccent_rules::str, str_tolower(), VARDATA_ANY, and VARSIZE_ANY_EXHDR.

Referenced by citext_pattern_cmp().

141 {
142  text *txt = PG_GETARG_TEXT_PP(0);
143  char *str;
144  Datum result;
145 
146  str = str_tolower(VARDATA_ANY(txt), VARSIZE_ANY_EXHDR(txt), DEFAULT_COLLATION_OID);
147  result = hash_any((unsigned char *) str, strlen(str));
148  pfree(str);
149 
150  /* Avoid leaking memory for toasted inputs */
151  PG_FREE_IF_COPY(txt, 0);
152 
153  PG_RETURN_DATUM(result);
154 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:348
Datum hash_any(const unsigned char *k, int keylen)
Definition: hashfn.c:148
char * str_tolower(const char *buff, size_t nbytes, Oid collid)
Definition: formatting.c:1645
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
void pfree(void *pointer)
Definition: mcxt.c:1056
uintptr_t Datum
Definition: postgres.h:367
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:343
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
Definition: c.h:549

◆ citext_hash_extended()

Datum citext_hash_extended ( PG_FUNCTION_ARGS  )

Definition at line 159 of file citext.c.

References citext_eq(), hash_any_extended(), pfree(), PG_FREE_IF_COPY, PG_FUNCTION_INFO_V1(), PG_GETARG_INT64, PG_GETARG_TEXT_PP, PG_RETURN_DATUM, generate_unaccent_rules::str, str_tolower(), VARDATA_ANY, and VARSIZE_ANY_EXHDR.

Referenced by citext_hash().

160 {
161  text *txt = PG_GETARG_TEXT_PP(0);
162  uint64 seed = PG_GETARG_INT64(1);
163  char *str;
164  Datum result;
165 
166  str = str_tolower(VARDATA_ANY(txt), VARSIZE_ANY_EXHDR(txt), DEFAULT_COLLATION_OID);
167  result = hash_any_extended((unsigned char *) str, strlen(str), seed);
168  pfree(str);
169 
170  /* Avoid leaking memory for toasted inputs */
171  PG_FREE_IF_COPY(txt, 0);
172 
173  PG_RETURN_DATUM(result);
174 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:348
char * str_tolower(const char *buff, size_t nbytes, Oid collid)
Definition: formatting.c:1645
Datum hash_any_extended(const unsigned char *k, int keylen, uint64 seed)
Definition: hashfn.c:374
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
void pfree(void *pointer)
Definition: mcxt.c:1056
uintptr_t Datum
Definition: postgres.h:367
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:343
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
Definition: c.h:549
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ citext_larger()

Datum citext_larger ( PG_FUNCTION_ARGS  )

Definition at line 400 of file citext.c.

References citextcmp(), PG_GET_COLLATION, PG_GETARG_TEXT_PP, and PG_RETURN_TEXT_P.

Referenced by citext_smaller().

401 {
402  text *left = PG_GETARG_TEXT_PP(0);
403  text *right = PG_GETARG_TEXT_PP(1);
404  text *result;
405 
406  result = citextcmp(left, right, PG_GET_COLLATION()) > 0 ? left : right;
407  PG_RETURN_TEXT_P(result);
408 }
static int32 citextcmp(text *left, text *right, Oid collid)
Definition: citext.c:35
#define PG_GET_COLLATION()
Definition: fmgr.h:193
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:361
Definition: c.h:549

◆ citext_le()

Datum citext_le ( PG_FUNCTION_ARGS  )

Definition at line 262 of file citext.c.

References citext_gt(), citextcmp(), PG_FREE_IF_COPY, PG_FUNCTION_INFO_V1(), PG_GET_COLLATION, PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

Referenced by citext_lt().

263 {
264  text *left = PG_GETARG_TEXT_PP(0);
265  text *right = PG_GETARG_TEXT_PP(1);
266  bool result;
267 
268  result = citextcmp(left, right, PG_GET_COLLATION()) <= 0;
269 
270  PG_FREE_IF_COPY(left, 0);
271  PG_FREE_IF_COPY(right, 1);
272 
273  PG_RETURN_BOOL(result);
274 }
static int32 citextcmp(text *left, text *right, Oid collid)
Definition: citext.c:35
#define PG_GET_COLLATION()
Definition: fmgr.h:193
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
Definition: c.h:549

◆ citext_lt()

Datum citext_lt ( PG_FUNCTION_ARGS  )

Definition at line 245 of file citext.c.

References citext_le(), citextcmp(), PG_FREE_IF_COPY, PG_FUNCTION_INFO_V1(), PG_GET_COLLATION, PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

Referenced by citext_ne().

246 {
247  text *left = PG_GETARG_TEXT_PP(0);
248  text *right = PG_GETARG_TEXT_PP(1);
249  bool result;
250 
251  result = citextcmp(left, right, PG_GET_COLLATION()) < 0;
252 
253  PG_FREE_IF_COPY(left, 0);
254  PG_FREE_IF_COPY(right, 1);
255 
256  PG_RETURN_BOOL(result);
257 }
static int32 citextcmp(text *left, text *right, Oid collid)
Definition: citext.c:35
#define PG_GET_COLLATION()
Definition: fmgr.h:193
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
Definition: c.h:549

◆ citext_ne()

Datum citext_ne ( PG_FUNCTION_ARGS  )

Definition at line 215 of file citext.c.

References citext_lt(), pfree(), PG_FREE_IF_COPY, PG_FUNCTION_INFO_V1(), PG_GETARG_TEXT_PP, PG_RETURN_BOOL, str_tolower(), VARDATA_ANY, and VARSIZE_ANY_EXHDR.

Referenced by citext_eq().

216 {
217  text *left = PG_GETARG_TEXT_PP(0);
218  text *right = PG_GETARG_TEXT_PP(1);
219  char *lcstr,
220  *rcstr;
221  bool result;
222 
223  /* We can't compare lengths in advance of downcasing ... */
224 
225  lcstr = str_tolower(VARDATA_ANY(left), VARSIZE_ANY_EXHDR(left), DEFAULT_COLLATION_OID);
226  rcstr = str_tolower(VARDATA_ANY(right), VARSIZE_ANY_EXHDR(right), DEFAULT_COLLATION_OID);
227 
228  /*
229  * Since we only care about equality or not-equality, we can avoid all the
230  * expense of strcoll() here, and just do bitwise comparison.
231  */
232  result = (strcmp(lcstr, rcstr) != 0);
233 
234  pfree(lcstr);
235  pfree(rcstr);
236  PG_FREE_IF_COPY(left, 0);
237  PG_FREE_IF_COPY(right, 1);
238 
239  PG_RETURN_BOOL(result);
240 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:348
char * str_tolower(const char *buff, size_t nbytes, Oid collid)
Definition: formatting.c:1645
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
void pfree(void *pointer)
Definition: mcxt.c:1056
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
Definition: c.h:549

◆ citext_pattern_cmp()

Datum citext_pattern_cmp ( PG_FUNCTION_ARGS  )

Definition at line 123 of file citext.c.

References citext_hash(), internal_citext_pattern_cmp(), PG_FREE_IF_COPY, PG_FUNCTION_INFO_V1(), PG_GET_COLLATION, PG_GETARG_TEXT_PP, and PG_RETURN_INT32.

Referenced by citext_cmp().

124 {
125  text *left = PG_GETARG_TEXT_PP(0);
126  text *right = PG_GETARG_TEXT_PP(1);
127  int32 result;
128 
129  result = internal_citext_pattern_cmp(left, right, PG_GET_COLLATION());
130 
131  PG_FREE_IF_COPY(left, 0);
132  PG_FREE_IF_COPY(right, 1);
133 
134  PG_RETURN_INT32(result);
135 }
static int32 internal_citext_pattern_cmp(text *left, text *right, Oid collid)
Definition: citext.c:68
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
#define PG_GET_COLLATION()
Definition: fmgr.h:193
signed int int32
Definition: c.h:346
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
Definition: c.h:549

◆ citext_pattern_ge()

Datum citext_pattern_ge ( PG_FUNCTION_ARGS  )

Definition at line 364 of file citext.c.

References citext_smaller(), internal_citext_pattern_cmp(), PG_FREE_IF_COPY, PG_FUNCTION_INFO_V1(), PG_GET_COLLATION, PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

Referenced by citext_pattern_gt().

365 {
366  text *left = PG_GETARG_TEXT_PP(0);
367  text *right = PG_GETARG_TEXT_PP(1);
368  bool result;
369 
370  result = internal_citext_pattern_cmp(left, right, PG_GET_COLLATION()) >= 0;
371 
372  PG_FREE_IF_COPY(left, 0);
373  PG_FREE_IF_COPY(right, 1);
374 
375  PG_RETURN_BOOL(result);
376 }
static int32 internal_citext_pattern_cmp(text *left, text *right, Oid collid)
Definition: citext.c:68
#define PG_GET_COLLATION()
Definition: fmgr.h:193
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
Definition: c.h:549

◆ citext_pattern_gt()

Datum citext_pattern_gt ( PG_FUNCTION_ARGS  )

Definition at line 347 of file citext.c.

References citext_pattern_ge(), internal_citext_pattern_cmp(), PG_FREE_IF_COPY, PG_FUNCTION_INFO_V1(), PG_GET_COLLATION, PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

Referenced by citext_pattern_le().

348 {
349  text *left = PG_GETARG_TEXT_PP(0);
350  text *right = PG_GETARG_TEXT_PP(1);
351  bool result;
352 
353  result = internal_citext_pattern_cmp(left, right, PG_GET_COLLATION()) > 0;
354 
355  PG_FREE_IF_COPY(left, 0);
356  PG_FREE_IF_COPY(right, 1);
357 
358  PG_RETURN_BOOL(result);
359 }
static int32 internal_citext_pattern_cmp(text *left, text *right, Oid collid)
Definition: citext.c:68
#define PG_GET_COLLATION()
Definition: fmgr.h:193
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
Definition: c.h:549

◆ citext_pattern_le()

Datum citext_pattern_le ( PG_FUNCTION_ARGS  )

Definition at line 330 of file citext.c.

References citext_pattern_gt(), internal_citext_pattern_cmp(), PG_FREE_IF_COPY, PG_FUNCTION_INFO_V1(), PG_GET_COLLATION, PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

Referenced by citext_pattern_lt().

331 {
332  text *left = PG_GETARG_TEXT_PP(0);
333  text *right = PG_GETARG_TEXT_PP(1);
334  bool result;
335 
336  result = internal_citext_pattern_cmp(left, right, PG_GET_COLLATION()) <= 0;
337 
338  PG_FREE_IF_COPY(left, 0);
339  PG_FREE_IF_COPY(right, 1);
340 
341  PG_RETURN_BOOL(result);
342 }
static int32 internal_citext_pattern_cmp(text *left, text *right, Oid collid)
Definition: citext.c:68
#define PG_GET_COLLATION()
Definition: fmgr.h:193
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
Definition: c.h:549

◆ citext_pattern_lt()

Datum citext_pattern_lt ( PG_FUNCTION_ARGS  )

Definition at line 313 of file citext.c.

References citext_pattern_le(), internal_citext_pattern_cmp(), PG_FREE_IF_COPY, PG_FUNCTION_INFO_V1(), PG_GET_COLLATION, PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

Referenced by citext_ge().

314 {
315  text *left = PG_GETARG_TEXT_PP(0);
316  text *right = PG_GETARG_TEXT_PP(1);
317  bool result;
318 
319  result = internal_citext_pattern_cmp(left, right, PG_GET_COLLATION()) < 0;
320 
321  PG_FREE_IF_COPY(left, 0);
322  PG_FREE_IF_COPY(right, 1);
323 
324  PG_RETURN_BOOL(result);
325 }
static int32 internal_citext_pattern_cmp(text *left, text *right, Oid collid)
Definition: citext.c:68
#define PG_GET_COLLATION()
Definition: fmgr.h:193
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
Definition: c.h:549

◆ citext_smaller()

Datum citext_smaller ( PG_FUNCTION_ARGS  )

Definition at line 387 of file citext.c.

References citext_larger(), citextcmp(), PG_FUNCTION_INFO_V1(), PG_GET_COLLATION, PG_GETARG_TEXT_PP, and PG_RETURN_TEXT_P.

Referenced by citext_pattern_ge().

388 {
389  text *left = PG_GETARG_TEXT_PP(0);
390  text *right = PG_GETARG_TEXT_PP(1);
391  text *result;
392 
393  result = citextcmp(left, right, PG_GET_COLLATION()) < 0 ? left : right;
394  PG_RETURN_TEXT_P(result);
395 }
static int32 citextcmp(text *left, text *right, Oid collid)
Definition: citext.c:35
#define PG_GET_COLLATION()
Definition: fmgr.h:193
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:361
Definition: c.h:549

◆ citextcmp()

static int32 citextcmp ( text left,
text right,
Oid  collid 
)
static

Definition at line 35 of file citext.c.

References pfree(), str_tolower(), VARDATA_ANY, VARSIZE_ANY_EXHDR, and varstr_cmp().

Referenced by citext_cmp(), citext_ge(), citext_gt(), citext_larger(), citext_le(), citext_lt(), and citext_smaller().

36 {
37  char *lcstr,
38  *rcstr;
39  int32 result;
40 
41  /*
42  * We must do our str_tolower calls with DEFAULT_COLLATION_OID, not the
43  * input collation as you might expect. This is so that the behavior of
44  * citext's equality and hashing functions is not collation-dependent. We
45  * should change this once the core infrastructure is able to cope with
46  * collation-dependent equality and hashing functions.
47  */
48 
49  lcstr = str_tolower(VARDATA_ANY(left), VARSIZE_ANY_EXHDR(left), DEFAULT_COLLATION_OID);
50  rcstr = str_tolower(VARDATA_ANY(right), VARSIZE_ANY_EXHDR(right), DEFAULT_COLLATION_OID);
51 
52  result = varstr_cmp(lcstr, strlen(lcstr),
53  rcstr, strlen(rcstr),
54  collid);
55 
56  pfree(lcstr);
57  pfree(rcstr);
58 
59  return result;
60 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:348
char * str_tolower(const char *buff, size_t nbytes, Oid collid)
Definition: formatting.c:1645
signed int int32
Definition: c.h:346
void pfree(void *pointer)
Definition: mcxt.c:1056
int varstr_cmp(const char *arg1, int len1, const char *arg2, int len2, Oid collid)
Definition: varlena.c:1474
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341

◆ internal_citext_pattern_cmp()

static int32 internal_citext_pattern_cmp ( text left,
text right,
Oid  collid 
)
static

Definition at line 68 of file citext.c.

References citext_cmp(), Min, pfree(), PG_FUNCTION_INFO_V1(), str_tolower(), VARDATA_ANY, and VARSIZE_ANY_EXHDR.

Referenced by citext_pattern_cmp(), citext_pattern_ge(), citext_pattern_gt(), citext_pattern_le(), and citext_pattern_lt().

69 {
70  char *lcstr,
71  *rcstr;
72  int llen,
73  rlen;
74  int32 result;
75 
76  lcstr = str_tolower(VARDATA_ANY(left), VARSIZE_ANY_EXHDR(left), DEFAULT_COLLATION_OID);
77  rcstr = str_tolower(VARDATA_ANY(right), VARSIZE_ANY_EXHDR(right), DEFAULT_COLLATION_OID);
78 
79  llen = strlen(lcstr);
80  rlen = strlen(rcstr);
81 
82  result = memcmp((void *) lcstr, (void *) rcstr, Min(llen, rlen));
83  if (result == 0)
84  {
85  if (llen < rlen)
86  result = -1;
87  else if (llen > rlen)
88  result = 1;
89  }
90 
91  pfree(lcstr);
92  pfree(rcstr);
93 
94  return result;
95 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:348
char * str_tolower(const char *buff, size_t nbytes, Oid collid)
Definition: formatting.c:1645
#define Min(x, y)
Definition: c.h:904
signed int int32
Definition: c.h:346
void pfree(void *pointer)
Definition: mcxt.c:1056
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341

◆ PG_FUNCTION_INFO_V1() [1/16]

◆ PG_FUNCTION_INFO_V1() [2/16]

PG_FUNCTION_INFO_V1 ( citext_pattern_cmp  )

◆ PG_FUNCTION_INFO_V1() [3/16]

PG_FUNCTION_INFO_V1 ( citext_hash  )

◆ PG_FUNCTION_INFO_V1() [4/16]

PG_FUNCTION_INFO_V1 ( citext_hash_extended  )

◆ PG_FUNCTION_INFO_V1() [5/16]

PG_FUNCTION_INFO_V1 ( citext_eq  )

◆ PG_FUNCTION_INFO_V1() [6/16]

PG_FUNCTION_INFO_V1 ( citext_ne  )

◆ PG_FUNCTION_INFO_V1() [7/16]

PG_FUNCTION_INFO_V1 ( citext_lt  )

◆ PG_FUNCTION_INFO_V1() [8/16]

PG_FUNCTION_INFO_V1 ( citext_le  )

◆ PG_FUNCTION_INFO_V1() [9/16]

PG_FUNCTION_INFO_V1 ( citext_gt  )

◆ PG_FUNCTION_INFO_V1() [10/16]

PG_FUNCTION_INFO_V1 ( citext_ge  )

◆ PG_FUNCTION_INFO_V1() [11/16]

PG_FUNCTION_INFO_V1 ( citext_pattern_lt  )

◆ PG_FUNCTION_INFO_V1() [12/16]

PG_FUNCTION_INFO_V1 ( citext_pattern_le  )

◆ PG_FUNCTION_INFO_V1() [13/16]

PG_FUNCTION_INFO_V1 ( citext_pattern_gt  )

◆ PG_FUNCTION_INFO_V1() [14/16]

PG_FUNCTION_INFO_V1 ( citext_pattern_ge  )

◆ PG_FUNCTION_INFO_V1() [15/16]

PG_FUNCTION_INFO_V1 ( citext_smaller  )

◆ PG_FUNCTION_INFO_V1() [16/16]

PG_FUNCTION_INFO_V1 ( citext_larger  )

Variable Documentation

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 12 of file citext.c.