1
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
3
This library is free software; you can redistribute it and/or
4
modify it under the terms of the GNU Library General Public
5
License as published by the Free Software Foundation; either
6
version 2 of the License, or (at your option) any later version.
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Library General Public License for more details.
13
You should have received a copy of the GNU Library General Public
14
License along with this library; if not, write to the Free
15
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18
/****************************************************************
19
* SOUNDEX ALGORITHM in C *
21
* The basic Algorithm source is taken from EDN Nov. *
24
* As a test Those in Illinois will find that the *
25
* first group of numbers in their drivers license *
26
* number is the soundex number for their last name. *
28
* RHW PC-IBBS ID. #1230 *
30
* As an extension if remove_garbage is set then all non- *
31
* alpha characters are skipped *
32
****************************************************************/
34
#include "mysys_priv.h"
36
#include "my_static.h"
38
static char get_scode(char **ptr,pbool remove_garbage);
40
/* outputed string is 4 byte long */
41
/* out_pntr can be == in_pntr */
43
void soundex(register my_string out_pntr, my_string in_pntr,
51
while (*in_pntr && isspace(*in_pntr)) /* Skipp pre-space */
54
*out_pntr++ = toupper(*in_pntr); /* Copy first letter */
55
last_ch = get_scode(&in_pntr,0); /* code of the first letter */
56
/* for the first 'double-letter */
58
end=out_pntr+3; /* Loop on input letters until */
59
/* end of input (null) or output */
60
/* letter code count = 3 */
63
while (out_pntr < end && (ch = get_scode(&in_pntr,remove_garbage)) != 0)
66
if ((ch != '0') && (ch != last_ch)) /* if not skipped or double */
68
*out_pntr++ = ch; /* letter, copy to output */
69
} /* for next double-letter check */
70
last_ch = ch; /* save code of last input letter */
72
while (out_pntr < end)
74
*out_pntr=0; /* end string */
80
If alpha, map input letter to soundex code.
81
If not alpha and remove_garbage is set then skipp to next char
85
static char get_scode(char **ptr, pbool remove_garbage)
91
while (**ptr && !isalpha(**ptr))
95
if (ch < 'A' || ch > 'Z')
97
if (isalpha(ch)) /* If exetended alfa (country spec) */
98
return '0'; /* threat as vokal */
99
return 0; /* Can't map */
101
return(soundex_map[ch-'A']);