mirror of
https://github.com/MariaDB/server.git
synced 2025-02-02 12:01:42 +01:00
cd21f7ce40
BitKeeper/etc/logging_ok: auto-union VC++Files/client/mysqlclient.dsp: Auto merged VC++Files/mysql.dsw: Auto merged extra/perror.c: Auto merged extra/replace.c: Auto merged innobase/configure.in: Auto merged innobase/include/lock0lock.h: Auto merged innobase/include/row0mysql.h: Auto merged innobase/include/sync0sync.h: Auto merged innobase/lock/lock0lock.c: Auto merged ltmain.sh: Auto merged BitKeeper/deleted/.del-libmysqld.def~8edf7b8780ce943c: Auto merged innobase/os/os0file.c: Auto merged innobase/pars/lexyy.c: Auto merged innobase/row/row0mysql.c: Auto merged innobase/srv/srv0srv.c: Auto merged innobase/srv/srv0start.c: Auto merged innobase/sync/sync0arr.c: Auto merged innobase/sync/sync0sync.c: Auto merged innobase/trx/trx0trx.c: Auto merged mysql-test/r/alias.result: Auto merged mysql-test/t/system_mysql_db_fix-master.opt: Auto merged mysql-test/r/func_time.result: Automatic merge mysql-test/r/innodb.result: Automatic merge mysql-test/t/alias.test: Automatic merge mysql-test/t/create.test: Automatic merge mysql-test/t/func_time.test: Automatic merge sql/ha_innodb.cc: Automatic merge sql/mysql_priv.h: Automatic merge mysql-test/r/rpl_multi_update.result: Automatic merge mysql-test/t/rpl_error_ignored_table.test: Automatic merge mysql-test/t/rpl_multi_update.test: Automatic merge sql/slave.h: Automatic merge sql/sql_base.cc: Automatic merge sql/sql_db.cc: Automatic merge sql/sql_insert.cc: Automatic merge sql/structs.h: Automatic merge sql/table.cc: Automatic merge strings/longlong2str-x86.s: Automatic merge strings/strings-x86.s: Automatic merge support-files/my-medium.cnf.sh: Automatic merge
106 lines
3.4 KiB
C
106 lines
3.4 KiB
C
/* Copyright (C) 2000 MySQL AB
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
/****************************************************************
|
|
* SOUNDEX ALGORITHM in C *
|
|
* *
|
|
* The basic Algorithm source is taken from EDN Nov. *
|
|
* 14, 1985 pg. 36. *
|
|
* *
|
|
* As a test Those in Illinois will find that the *
|
|
* first group of numbers in their drivers license *
|
|
* number is the soundex number for their last name. *
|
|
* *
|
|
* RHW PC-IBBS ID. #1230 *
|
|
* *
|
|
* As an extension if remove_garbage is set then all non- *
|
|
* alpha characters are skipped *
|
|
* *
|
|
* Note, that this implementation corresponds to the *
|
|
* original version of the algorithm, not to the more *
|
|
* popular "enhanced" version, described by Knuth. *
|
|
****************************************************************/
|
|
|
|
#include "mysys_priv.h"
|
|
#include <m_ctype.h>
|
|
#include "my_static.h"
|
|
|
|
static char get_scode(CHARSET_INFO * cs, char **ptr,pbool remove_garbage);
|
|
|
|
/* outputed string is 4 byte long */
|
|
/* out_pntr can be == in_pntr */
|
|
|
|
void soundex(CHARSET_INFO * cs,register my_string out_pntr, my_string in_pntr,
|
|
pbool remove_garbage)
|
|
{
|
|
char ch,last_ch;
|
|
reg3 my_string end;
|
|
register uchar *map=cs->to_upper;
|
|
|
|
if (remove_garbage)
|
|
{
|
|
while (*in_pntr && !my_isalpha(cs,*in_pntr)) /* Skipp pre-space */
|
|
in_pntr++;
|
|
}
|
|
*out_pntr++ = map[(uchar)*in_pntr]; /* Copy first letter */
|
|
last_ch = get_scode(cs,&in_pntr,0); /* code of the first letter */
|
|
/* for the first 'double-letter */
|
|
/* check. */
|
|
end=out_pntr+3; /* Loop on input letters until */
|
|
/* end of input (null) or output */
|
|
/* letter code count = 3 */
|
|
|
|
in_pntr++;
|
|
while (out_pntr < end && (ch = get_scode(cs,&in_pntr,remove_garbage)) != 0)
|
|
{
|
|
in_pntr++;
|
|
if ((ch != '0') && (ch != last_ch)) /* if not skipped or double */
|
|
{
|
|
*out_pntr++ = ch; /* letter, copy to output */
|
|
} /* for next double-letter check */
|
|
last_ch = ch; /* save code of last input letter */
|
|
}
|
|
while (out_pntr < end)
|
|
*out_pntr++ = '0';
|
|
*out_pntr=0; /* end string */
|
|
return;
|
|
} /* soundex */
|
|
|
|
|
|
/*
|
|
If alpha, map input letter to soundex code.
|
|
If not alpha and remove_garbage is set then skipp to next char
|
|
else return 0
|
|
*/
|
|
|
|
static char get_scode(CHARSET_INFO * cs,char **ptr, pbool remove_garbage)
|
|
{
|
|
uchar ch;
|
|
|
|
if (remove_garbage)
|
|
{
|
|
while (**ptr && !my_isalpha(cs,**ptr))
|
|
(*ptr)++;
|
|
}
|
|
ch=my_toupper(cs,**ptr);
|
|
if (ch < 'A' || ch > 'Z')
|
|
{
|
|
if (my_isalpha(cs,ch)) /* If extended alfa (country spec) */
|
|
return '0'; /* threat as vokal */
|
|
return 0; /* Can't map */
|
|
}
|
|
return(soundex_map[ch-'A']);
|
|
} /* get_scode */
|