convert_to_string_ex(str2);
distance = reference_levdist(Z_STRVAL_PP(str1), Z_STRLEN_PP(str1),
- Z_STRVAL_PP(str2), Z_STRLEN_PP(str2),
- 1, 1, 1);
+ Z_STRVAL_PP(str2), Z_STRLEN_PP(str2), 1, 1, 1);
break;
convert_to_long_ex(cost_rep);
convert_to_long_ex(cost_del);
- distance = reference_levdist(Z_STRVAL_PP(str1), Z_STRLEN_PP(str1),
- Z_STRVAL_PP(str2), Z_STRLEN_PP(str2),
- Z_LVAL_PP(cost_ins),
- Z_LVAL_PP(cost_rep),
- Z_LVAL_PP(cost_del)
- );
+ distance = reference_levdist(Z_STRVAL_PP(str1), Z_STRLEN_PP(str1),
+ Z_STRVAL_PP(str2), Z_STRLEN_PP(str2),
+ Z_LVAL_PP(cost_ins), Z_LVAL_PP(cost_rep),
+ Z_LVAL_PP(cost_del));
break;
convert_to_string_ex(str2);
convert_to_string_ex(callback_name);
- distance = custom_levdist(Z_STRVAL_PP(str1)
- , Z_STRVAL_PP(str2)
- , Z_STRVAL_PP(callback_name)
- );
+ distance = custom_levdist(Z_STRVAL_PP(str1), Z_STRVAL_PP(str2),
+ Z_STRVAL_PP(callback_name));
break;
default:
Break english phrases down into their phonemes */
PHP_FUNCTION(metaphone)
{
- pval **pstr, **pphones;
+ char *str;
char *result = 0;
- int phones = 0;
+ int phones = 0, str_len;
- if (zend_get_parameters_ex(2, &pstr, &pphones) == SUCCESS) {
- convert_to_long_ex(pphones);
- phones = Z_LVAL_PP(pphones);
- } else if (zend_get_parameters_ex(1, &pstr) == FAILURE) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &str_len,
+ &phones) == FAILURE) {
+ return;
}
- convert_to_string_ex(pstr);
-
- if (metaphone(Z_STRVAL_PP(pstr), phones, &result, 1) == 0) {
+ if (metaphone(str, phones, &result, 1) == 0) {
RETVAL_STRING(result, 0);
} else {
if (result) {
Calculate the soundex key of a string */
PHP_FUNCTION(soundex)
{
- char *somestring;
- int i, _small, len, code, last;
- pval *arg, **parg;
+ char *str;
+ int i, _small, str_len, code, last;
char soundex[4 + 1];
static char soundex_table[26] =
0, /* Y */
'2'}; /* Z */
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &parg) == FAILURE) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) {
+ return;
}
- convert_to_string_ex(parg);
- arg = *parg;
- if (Z_STRLEN_P(arg)==0) {
+ if (str_len == 0) {
RETURN_FALSE;
}
- somestring = Z_STRVAL_P(arg);
- len = Z_STRLEN_P(arg);
/* build soundex string */
last = -1;
- for (i = 0, _small = 0; i < len && _small < 4; i++) {
+ for (i = 0, _small = 0; i < str_len && _small < 4; i++) {
/* convert chars to upper case and strip non-letter chars */
/* BUG: should also map here accented letters used in non */
/* English words or names (also found in English text!): */
/* esstsett, thorn, n-tilde, c-cedilla, s-caron, ... */
- code = toupper(somestring[i]);
+ code = toupper(str[i]);
if (code >= 'A' && code <= 'Z') {
if (_small == 0) {
/* remember first valid char */
}
soundex[_small] = '\0';
- Z_STRVAL_P(return_value) = estrndup(soundex, _small);
- Z_STRLEN_P(return_value) = _small;
- Z_TYPE_P(return_value) = IS_STRING;
+ RETURN_STRINGL(soundex, _small, 1);
}
/* }}} */