|
5 | 5 | *
|
6 | 6 | * Joe Conway <mail@joeconway.com>
|
7 | 7 | *
|
8 |
| - * $PostgreSQL: pgsql/contrib/fuzzystrmatch/fuzzystrmatch.c,v 1.28 2009/01/01 17:23:32 momjian Exp $ |
| 8 | + * $PostgreSQL: pgsql/contrib/fuzzystrmatch/fuzzystrmatch.c,v 1.29 2009/04/07 15:53:54 tgl Exp $ |
9 | 9 | * Copyright (c) 2001-2009, PostgreSQL Global Development Group
|
10 | 10 | * ALL RIGHTS RESERVED;
|
11 | 11 | *
|
@@ -74,7 +74,15 @@ static void _soundex(const char *instr, char *outstr);
|
74 | 74 | /*ABCDEFGHIJKLMNOPQRSTUVWXYZ */
|
75 | 75 | staticconstchar*soundex_table="01230120022455012623010202";
|
76 | 76 |
|
77 |
| -#definesoundex_code(letter) soundex_table[toupper((unsigned char) (letter)) - 'A'] |
| 77 | +staticchar |
| 78 | +soundex_code(charletter) |
| 79 | +{ |
| 80 | +letter=toupper((unsignedchar)letter); |
| 81 | +/* Defend against non-ASCII letters */ |
| 82 | +if (letter >='A'&&letter <='Z') |
| 83 | +returnsoundex_table[letter-'A']; |
| 84 | +returnletter; |
| 85 | +} |
78 | 86 |
|
79 | 87 |
|
80 | 88 | /*
|
@@ -143,27 +151,37 @@ static int_metaphone(char *word, int max_phonemes, char **phoned_word);
|
143 | 151 |
|
144 | 152 | /*-- Character encoding array & accessing macros --*/
|
145 | 153 | /* Stolen directly out of the book... */
|
146 |
| -char_codes[26]= { |
| 154 | +staticconstchar_codes[26]= { |
147 | 155 | 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
|
148 | 156 | /*a b cd e f g h i j k l m n o p q r s t u v w x y z */
|
149 | 157 | };
|
150 | 158 |
|
| 159 | +staticint |
| 160 | +getcode(charc) |
| 161 | +{ |
| 162 | +if (isalpha((unsignedchar)c)) |
| 163 | +{ |
| 164 | +c=toupper((unsignedchar)c); |
| 165 | +/* Defend against non-ASCII letters */ |
| 166 | +if (c >='A'&&c <='Z') |
| 167 | +return_codes[c-'A']; |
| 168 | +} |
| 169 | +return0; |
| 170 | +} |
151 | 171 |
|
152 |
| -#defineENCODE(c) (isalpha((unsigned char) (c)) ? _codes[((toupper((unsigned char) (c))) - 'A')] : 0) |
153 |
| - |
154 |
| -#defineisvowel(c)(ENCODE(c) & 1)/* AEIOU */ |
| 172 | +#defineisvowel(c)(getcode(c) & 1)/* AEIOU */ |
155 | 173 |
|
156 | 174 | /* These letters are passed through unchanged */
|
157 |
| -#defineNOCHANGE(c) (ENCODE(c) & 2)/* FJMNR */ |
| 175 | +#defineNOCHANGE(c) (getcode(c) & 2)/* FJMNR */ |
158 | 176 |
|
159 | 177 | /* These form dipthongs when preceding H */
|
160 |
| -#defineAFFECTH(c)(ENCODE(c) & 4)/* CGPST */ |
| 178 | +#defineAFFECTH(c)(getcode(c) & 4)/* CGPST */ |
161 | 179 |
|
162 | 180 | /* These make C and G soft */
|
163 |
| -#defineMAKESOFT(c) (ENCODE(c) & 8)/* EIY */ |
| 181 | +#defineMAKESOFT(c) (getcode(c) & 8)/* EIY */ |
164 | 182 |
|
165 | 183 | /* These prevent GH from becoming F */
|
166 |
| -#defineNOGHTOF(c)(ENCODE(c) & 16)/* BDH */ |
| 184 | +#defineNOGHTOF(c)(getcode(c) & 16)/* BDH */ |
167 | 185 |
|
168 | 186 |
|
169 | 187 | /*
|
|