53 static void _soundex(
const char *instr,
char *outstr);
63 letter = toupper((
unsigned char) letter);
65 if (letter >=
'A' && letter <=
'Z')
73 #define MAX_METAPHONE_STRLEN 255
101 #undef USE_TRADITIONAL_METAPHONE
108 static void _metaphone(
char *
word,
int max_phonemes,
char **phoned_word);
116 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
123 if (isalpha((
unsigned char)
c))
125 c = toupper((
unsigned char)
c);
127 if (
c >=
'A' &&
c <=
'Z')
133 #define isvowel(c) (getcode(c) & 1)
136 #define NOCHANGE(c) (getcode(c) & 2)
139 #define AFFECTH(c) (getcode(c) & 4)
142 #define MAKESOFT(c) (getcode(c) & 8)
145 #define NOGHTOF(c) (getcode(c) & 16)
169 ins_c, del_c, sub_c,
false));
261 size_t str_i_len = strlen(str_i);
266 if (!(str_i_len > 0))
271 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
272 errmsg(
"argument exceeds the maximum length of %d bytes",
278 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
279 errmsg(
"output exceeds the maximum length of %d bytes",
284 (
errcode(ERRCODE_ZERO_LENGTH_CHARACTER_STRING),
285 errmsg(
"output cannot be empty string")));
302 #define Next_Letter (toupper((unsigned char) word[w_idx+1]))
304 #define Curr_Letter (toupper((unsigned char) word[w_idx]))
306 #define Look_Back_Letter(n) \
307 (w_idx >= (n) ? toupper((unsigned char) word[w_idx-(n)]) : '\0')
309 #define Prev_Letter (Look_Back_Letter(1))
311 #define After_Next_Letter \
312 (Next_Letter != '\0' ? toupper((unsigned char) word[w_idx+2]) : '\0')
313 #define Look_Ahead_Letter(n) toupper((unsigned char) Lookahead(word+w_idx, n))
321 char letter_ahead =
'\0';
334 #define Phonize(c) do {(*phoned_word)[p_idx++] = c;} while (0)
336 #define End_Phoned_Word do {(*phoned_word)[p_idx] = '\0';} while (0)
338 #define Phone_Len (p_idx)
341 #define Isbreak(c) (!isalpha((unsigned char) (c)))
359 if (!(max_phonemes > 0))
361 elog(
ERROR,
"metaphone: Requested output length must be > 0");
364 if ((
word == NULL) || !(strlen(
word) > 0))
366 elog(
ERROR,
"metaphone: Input string length must be > 0");
369 if (max_phonemes == 0)
371 *phoned_word =
palloc(
sizeof(
char) * strlen(
word) + 1);
375 *phoned_word =
palloc(
sizeof(
char) * max_phonemes + 1);
380 for (; !isalpha((
unsigned char) (
Curr_Letter)); w_idx++)
460 (max_phonemes == 0 ||
Phone_Len < max_phonemes);
467 unsigned short int skip_letter = 0;
518 #ifndef USE_TRADITIONAL_METAPHONE
631 #ifndef USE_TRADITIONAL_METAPHONE
672 if (max_phonemes == 0 ||
Phone_Len < max_phonemes)
698 w_idx += skip_letter;
732 while (*instr && !isalpha((
unsigned char) *instr))
743 *outstr++ = (char) toupper((
unsigned char) *instr++);
748 if (isalpha((
unsigned char) *instr) &&
789 if (sndx1[
i] == sndx2[
i])
Datum idx(PG_FUNCTION_ARGS)
#define TextDatumGetCString(d)
#define Assert(condition)
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)
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)
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)
char * text_to_cstring(const text *t)
text * cstring_to_text(const char *s)
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)