cvs: php4 /ext/standard levenshtein.c metaphone.c soundex.c

From: Date: Fri, 19 Oct 2001 19:21:58 +0000
Subject: cvs: php4 /ext/standard levenshtein.c metaphone.c soundex.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-7875@lists.php.net to get a copy of this message
andrei Fri Oct 19 15:21:58 2001 EDT Modified files: /php4/ext/standard levenshtein.c metaphone.c soundex.c Log: Converting to use new parameter parsing API. Index: php4/ext/standard/levenshtein.c diff -u php4/ext/standard/levenshtein.c:1.20 php4/ext/standard/levenshtein.c:1.21 --- php4/ext/standard/levenshtein.c:1.20 Tue Sep 25 18:48:43 2001 +++ php4/ext/standard/levenshtein.c Fri Oct 19 15:21:58 2001 @@ -15,7 +15,7 @@ | Author: Hartmut Holzgraefe <hartmut@six.de> | +----------------------------------------------------------------------+ */ -/* $Id: levenshtein.c,v 1.20 2001/09/25 22:48:43 jeroen Exp $ */ +/* $Id: levenshtein.c,v 1.21 2001/10/19 19:21:58 andrei Exp $ */ #include "php.h" #include <stdlib.h> @@ -102,8 +102,7 @@ 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; @@ -117,12 +116,10 @@ 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; @@ -134,10 +131,8 @@ 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: Index: php4/ext/standard/metaphone.c diff -u php4/ext/standard/metaphone.c:1.17 php4/ext/standard/metaphone.c:1.18 --- php4/ext/standard/metaphone.c:1.17 Tue Sep 25 17:58:23 2001 +++ php4/ext/standard/metaphone.c Fri Oct 19 15:21:58 2001 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: metaphone.c,v 1.17 2001/09/25 21:58:23 jeroen Exp $ */ +/* $Id: metaphone.c,v 1.18 2001/10/19 19:21:58 andrei Exp $ */ /* Based on CPANs "Text-Metaphone-1.96" by Michael G Schwern <schwern@pobox.com> @@ -33,20 +33,16 @@ 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) { Index: php4/ext/standard/soundex.c diff -u php4/ext/standard/soundex.c:1.18 php4/ext/standard/soundex.c:1.19 --- php4/ext/standard/soundex.c:1.18 Tue Sep 25 17:58:24 2001 +++ php4/ext/standard/soundex.c Fri Oct 19 15:21:58 2001 @@ -15,7 +15,7 @@ | Author: Bjørn Borud - Guardian Networks AS <borud@guardian.no> | +----------------------------------------------------------------------+ */ -/* $Id: soundex.c,v 1.18 2001/09/25 21:58:24 jeroen Exp $ */ +/* $Id: soundex.c,v 1.19 2001/10/19 19:21:58 andrei Exp $ */ #include "php.h" #include <stdlib.h> @@ -28,9 +28,8 @@ 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] = @@ -61,25 +60,21 @@ 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 */ @@ -106,9 +101,7 @@ } 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); } /* }}} */

« previous php.cvs (#7875) next »