Commit eba6082a authored by Guido van Rossum's avatar Guido van Rossum

Add case for 'R' and a little bit of cleanup. Andrew Kuchling.

parent e11f7aab
...@@ -26,7 +26,7 @@ static void soundex_hash(char *str, char *result) ...@@ -26,7 +26,7 @@ static void soundex_hash(char *str, char *result)
char *sptr = str; /* pointer into str */ char *sptr = str; /* pointer into str */
char *rptr = result; /* pointer into result */ char *rptr = result; /* pointer into result */
if(*str == NULL) if(*str == '\0')
{ {
strcpy(result,"000000"); strcpy(result,"000000");
return; return;
...@@ -39,19 +39,20 @@ static void soundex_hash(char *str, char *result) ...@@ -39,19 +39,20 @@ static void soundex_hash(char *str, char *result)
/* Translate the rest of the input string into result. The following /* Translate the rest of the input string into result. The following
transformations are used: transformations are used:
1) All vowles, W, and H, are skipped. 1) All vowels, W, and H, are skipped.
2) BFPV = 1 2) BFPV = 1
CGJKQSXZ = 2 CGJKQSXZ = 2
DT = 3 DT = 3
L = 4 L = 4
MN = 5 MN = 5
R = 6
3) Only translate the first of adjacent equal translations. I.E. 3) Only translate the first of adjacent equal translations. I.E.
remove duplicate digits. remove duplicate digits.
*/ */
for(;(rptr - result) < 6 && *sptr != NULL;sptr++) for(;(rptr - result) < 6 && *sptr != '\0';sptr++)
{ {
switch (toupper(*sptr)) switch (toupper(*sptr))
{ {
...@@ -95,6 +96,9 @@ static void soundex_hash(char *str, char *result) ...@@ -95,6 +96,9 @@ static void soundex_hash(char *str, char *result)
if(*(rptr - 1) != '5') if(*(rptr - 1) != '5')
*(rptr++) = '5'; *(rptr++) = '5';
break; break;
case 'R':
if(*(rptr -1) != '6')
*(rptr++) = '6';
default: default:
break; break;
} }
...@@ -107,7 +111,7 @@ static void soundex_hash(char *str, char *result) ...@@ -107,7 +111,7 @@ static void soundex_hash(char *str, char *result)
/* Terminate the result string. /* Terminate the result string.
*/ */
*(result + 6) = NULL; *(result + 6) = '\0';
} }
...@@ -119,7 +123,6 @@ static PyObject * ...@@ -119,7 +123,6 @@ static PyObject *
get_soundex(PyObject *self, PyObject *args) get_soundex(PyObject *self, PyObject *args)
{ {
char *str; char *str;
int retval;
char sdx[7]; char sdx[7];
if(!PyArg_ParseTuple( args, "s", &str)) if(!PyArg_ParseTuple( args, "s", &str))
...@@ -136,7 +139,6 @@ static PyObject * ...@@ -136,7 +139,6 @@ static PyObject *
sound_similar(PyObject *self, PyObject *args) sound_similar(PyObject *self, PyObject *args)
{ {
char *str1, *str2; char *str1, *str2;
int return_value;
char res1[7], res2[7]; char res1[7], res2[7];
if(!PyArg_ParseTuple(args, "ss", &str1, &str2)) if(!PyArg_ParseTuple(args, "ss", &str1, &str2))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment