]> granicus.if.org Git - php/commitdiff
Converting to use new parameter parsing API.
authorAndrei Zmievski <andrei@php.net>
Fri, 19 Oct 2001 19:21:58 +0000 (19:21 +0000)
committerAndrei Zmievski <andrei@php.net>
Fri, 19 Oct 2001 19:21:58 +0000 (19:21 +0000)
ext/standard/levenshtein.c
ext/standard/metaphone.c
ext/standard/soundex.c

index 129044128c7b881fc7f5f78e75da9a52e655d50a..984b37044ef83d4e2c54f1d50ecb7f907a97e530 100644 (file)
@@ -102,8 +102,7 @@ PHP_FUNCTION(levenshtein)
                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 @@ PHP_FUNCTION(levenshtein)
                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 @@ PHP_FUNCTION(levenshtein)
                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 5d1648dfd2c498aa4e74ca9578487bad0466f8ce..d46a7464d2cc7842f8512947f373dfedda5c9c52 100644 (file)
@@ -33,20 +33,16 @@ PHP_FUNCTION(metaphone);
    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 bea945117b2fa3e3ba5006a708bb4278317f257e..c827e9614c8d3f9ff5a43043cf7f3cb226eec0a7 100644 (file)
@@ -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 @@ PHP_FUNCTION(soundex)
         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 @@ PHP_FUNCTION(soundex)
        }
        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);
 }
 /* }}} */