48 .
name =
"fuzzystrmatch",
55static void _soundex(
const char *instr,
char *outstr);
65 letter = toupper((
unsigned char) letter);
67 if (letter >=
'A' && letter <=
'Z')
75#define MAX_METAPHONE_STRLEN 255
103#undef USE_TRADITIONAL_METAPHONE
110static void _metaphone(
char *
word,
int max_phonemes,
char **phoned_word);
118 1, 16, 4, 16, 9, 2, 4, 16, 9, 2, 0, 2, 2, 2, 1, 4, 0, 2, 4, 4, 1, 0, 0, 0, 8, 0
125 if (isalpha((
unsigned char)
c))
127 c = toupper((
unsigned char)
c);
129 if (
c >=
'A' &&
c <=
'Z')
135#define isvowel(c) (getcode(c) & 1)
138#define NOCHANGE(c) (getcode(c) & 2)
141#define AFFECTH(c) (getcode(c) & 4)
144#define MAKESOFT(c) (getcode(c) & 8)
147#define NOGHTOF(c) (getcode(c) & 16)
171 ins_c, del_c, sub_c,
false));
263 size_t str_i_len = strlen(str_i);
268 if (!(str_i_len > 0))
273 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
274 errmsg(
"argument exceeds the maximum length of %d bytes",
280 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
281 errmsg(
"output exceeds the maximum length of %d bytes",
286 (
errcode(ERRCODE_ZERO_LENGTH_CHARACTER_STRING),
287 errmsg(
"output cannot be empty string")));
304#define Next_Letter (toupper((unsigned char) word[w_idx+1]))
306#define Curr_Letter (toupper((unsigned char) word[w_idx]))
308#define Look_Back_Letter(n) \
309 (w_idx >= (n) ? toupper((unsigned char) word[w_idx-(n)]) : '\0')
311#define Prev_Letter (Look_Back_Letter(1))
313#define After_Next_Letter \
314 (Next_Letter != '\0' ? toupper((unsigned char) word[w_idx+2]) : '\0')
315#define Look_Ahead_Letter(n) toupper((unsigned char) Lookahead(word+w_idx, n))
323 char letter_ahead =
'\0';
336#define Phonize(c) do {(*phoned_word)[p_idx++] = c;} while (0)
338#define End_Phoned_Word do {(*phoned_word)[p_idx] = '\0';} while (0)
340#define Phone_Len (p_idx)
343#define Isbreak(c) (!isalpha((unsigned char) (c)))
361 if (!(max_phonemes > 0))
363 elog(
ERROR,
"metaphone: Requested output length must be > 0");
366 if ((
word == NULL) || !(strlen(
word) > 0))
368 elog(
ERROR,
"metaphone: Input string length must be > 0");
371 if (max_phonemes == 0)
373 *phoned_word =
palloc(
sizeof(
char) * strlen(
word) + 1);
377 *phoned_word =
palloc(
sizeof(
char) * max_phonemes + 1);
382 for (; !isalpha((
unsigned char) (
Curr_Letter)); w_idx++)
462 (max_phonemes == 0 ||
Phone_Len < max_phonemes);
469 unsigned short int skip_letter = 0;
520#ifndef USE_TRADITIONAL_METAPHONE
633#ifndef USE_TRADITIONAL_METAPHONE
674 if (max_phonemes == 0 ||
Phone_Len < max_phonemes)
700 w_idx += skip_letter;
734 while (*instr && !isalpha((
unsigned char) *instr))
745 *outstr++ = (char) toupper((
unsigned char) *instr++);
750 if (isalpha((
unsigned char) *instr) &&
791 if (sndx1[
i] == sndx2[
i])
Datum idx(PG_FUNCTION_ARGS)
#define TextDatumGetCString(d)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define PG_GETARG_TEXT_PP(n)
#define PG_GETARG_DATUM(n)
#define PG_RETURN_TEXT_P(x)
#define PG_RETURN_INT32(x)
#define PG_GETARG_INT32(n)
Datum metaphone(PG_FUNCTION_ARGS)
static void _metaphone(char *word, int max_phonemes, char **phoned_word)
#define After_Next_Letter
Datum levenshtein_less_equal_with_costs(PG_FUNCTION_ARGS)
#define Look_Back_Letter(n)
static const char *const soundex_table
Datum soundex(PG_FUNCTION_ARGS)
static char soundex_code(char letter)
static const char _codes[26]
Datum levenshtein_with_costs(PG_FUNCTION_ARGS)
PG_MODULE_MAGIC_EXT(.name="fuzzystrmatch",.version=PG_VERSION)
static void _soundex(const char *instr, char *outstr)
static int getcode(char c)
Datum difference(PG_FUNCTION_ARGS)
#define MAX_METAPHONE_STRLEN
static char Lookahead(char *word, int how_far)
Datum levenshtein_less_equal(PG_FUNCTION_ARGS)
#define Look_Ahead_Letter(n)
PG_FUNCTION_INFO_V1(levenshtein_with_costs)
Datum levenshtein(PG_FUNCTION_ARGS)
Assert(PointerIsAligned(start, uint64))
int varstr_levenshtein(const char *source, int slen, const char *target, int tlen, int ins_c, int del_c, int sub_c, bool trusted)
static void word(struct vars *v, int dir, struct state *lp, struct state *rp)
#define VARSIZE_ANY_EXHDR(PTR)
text * cstring_to_text(const char *s)
char * text_to_cstring(const text *t)
int varstr_levenshtein_less_equal(const char *source, int slen, const char *target, int tlen, int ins_c, int del_c, int sub_c, int max_d, bool trusted)