1 /*-------------------------------------------------------------------------
4 * Text search dictionary for integers
6 * Copyright (c) 2007-2008, PostgreSQL Global Development Group
11 *-------------------------------------------------------------------------
15 #include "commands/defrem.h"
17 #include "tsearch/ts_public.h"
29 PG_FUNCTION_INFO_V1(dintdict_init
);
30 Datum
dintdict_init(PG_FUNCTION_ARGS
);
32 PG_FUNCTION_INFO_V1(dintdict_lexize
);
33 Datum
dintdict_lexize(PG_FUNCTION_ARGS
);
36 dintdict_init(PG_FUNCTION_ARGS
)
38 List
*dictoptions
= (List
*) PG_GETARG_POINTER(0);
42 d
= (DictInt
*) palloc0(sizeof(DictInt
));
44 d
->rejectlong
= false;
46 foreach(l
, dictoptions
)
48 DefElem
*defel
= (DefElem
*) lfirst(l
);
50 if (pg_strcasecmp(defel
->defname
, "MAXLEN") == 0)
52 d
->maxlen
= atoi(defGetString(defel
));
54 else if (pg_strcasecmp(defel
->defname
, "REJECTLONG") == 0)
56 d
->rejectlong
= defGetBoolean(defel
);
61 (errcode(ERRCODE_INVALID_PARAMETER_VALUE
),
62 errmsg("unrecognized intdict parameter: \"%s\"",
71 dintdict_lexize(PG_FUNCTION_ARGS
)
73 DictInt
*d
= (DictInt
*) PG_GETARG_POINTER(0);
74 char *in
= (char *) PG_GETARG_POINTER(1);
75 char *txt
= pnstrdup(in
, PG_GETARG_INT32(2));
76 TSLexeme
*res
= palloc(sizeof(TSLexeme
) * 2);
79 if (PG_GETARG_INT32(2) > d
->maxlen
)
83 /* reject by returning void array */
90 txt
[d
->maxlen
] = '\0';
99 PG_RETURN_POINTER(res
);