/* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 5e8cd8c22edadede2814b26b6fb984f1c3626850 */
+ * Stub hash: 5d9126adf07f6f480b5879f551de466140b98462 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0)
ZEND_END_ARG_INFO()
#endif
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_metaphone, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_metaphone, 0, 1, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, text, IS_STRING, 0)
- ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, phones, IS_LONG, 0, "0")
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, phonemes, IS_LONG, 0, "0")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_header, 0, 1, IS_VOID, 0)
#include "php.h"
-static int metaphone(unsigned char *word, size_t word_len, zend_long max_phonemes, zend_string **phoned_word, int traditional);
+static void metaphone(unsigned char *word, size_t word_len, zend_long max_phonemes, zend_string **phoned_word, int traditional);
/* {{{ Break english phrases down into their phonemes */
PHP_FUNCTION(metaphone)
Z_PARAM_LONG(phones)
ZEND_PARSE_PARAMETERS_END();
- if (metaphone((unsigned char *)ZSTR_VAL(str), ZSTR_LEN(str), phones, &result, 1) == 0) {
- RETVAL_STR(result);
- } else {
- if (result) {
- zend_string_free(result);
- }
- RETURN_FALSE;
+ if (phones < 0) {
+ zend_argument_value_error(2, "must be greater than or equal to 0");
+ RETURN_THROWS();
}
+
+ metaphone((unsigned char *)ZSTR_VAL(str), ZSTR_LEN(str), phones, &result, 1);
+ RETVAL_STR(result);
}
/* }}} */
ZSTR_LEN(*phoned_word) = p_idx; \
}
/* Slap a null character on the end of the phoned word */
-#define End_Phoned_Word { \
+#define End_Phoned_Word() { \
if (p_idx == max_buffer_len) { \
*phoned_word = zend_string_extend(*phoned_word, 1 * sizeof(char) + max_buffer_len, 0); \
max_buffer_len += 1; \
#define Isbreak(c) (!isalpha(c))
/* {{{ metaphone */
-static int metaphone(unsigned char *word, size_t word_len, zend_long max_phonemes, zend_string **phoned_word, int traditional)
+static void metaphone(unsigned char *word, size_t word_len, zend_long max_phonemes, zend_string **phoned_word, int traditional)
{
int w_idx = 0; /* point in the phonization we're at. */
size_t p_idx = 0; /* end of the phoned phrase */
size_t max_buffer_len = 0; /* maximum length of the destination buffer */
-
-/*-- Parameter checks --*/
- /* Negative phoneme length is meaningless */
-
- if (max_phonemes < 0)
- return -1;
-
- /* Empty/null string is meaningless */
- /* Overly paranoid */
- /* assert(word != NULL && word[0] != '\0'); */
-
- if (word == NULL)
- return -1;
+ ZEND_ASSERT(word != NULL);
+ ZEND_ASSERT(max_phonemes >= 0);
/*-- Allocate memory for our phoned_phrase --*/
if (max_phonemes == 0) { /* Assume largest possible */
for (; !isalpha(Curr_Letter); w_idx++) {
/* On the off chance we were given nothing but crap... */
if (Curr_Letter == '\0') {
- End_Phoned_Word
- return SUCCESS; /* For testing */
+ End_Phoned_Word();
+ return;
}
}
w_idx += skip_letter;
} /* END FOR */
- End_Phoned_Word;
-
- return 0;
+ End_Phoned_Word();
} /* END metaphone */
/* }}} */
var_dump(metaphone(""));
var_dump(metaphone(-1));
-var_dump(metaphone(-1, -1));
-var_dump(metaphone("valid phrase", -1));
+try {
+ var_dump(metaphone("valid phrase", -1));
+} catch (ValueError $e) {
+ echo $e->getMessage(), "\n";
+}
var_dump(metaphone("valid phrase", 0));
var_dump(metaphone("valid phrase", 10000));
--EXPECT--
string(0) ""
string(0) ""
-bool(false)
-bool(false)
+metaphone(): Argument #2 ($phonemes) must be greater than or equal to 0
string(6) "FLTFRS"
string(6) "FLTFRS"
string(26) "0FLFRWRTKRFLNKHTLSLN0KLTR0"