20
20
21
21
#include "php.h"
22
22
23
- static int metaphone (unsigned char * word , size_t word_len , zend_long max_phonemes , zend_string * * phoned_word , int traditional );
23
+ static void metaphone (unsigned char * word , size_t word_len , zend_long max_phonemes , zend_string * * phoned_word , int traditional );
24
24
25
25
/* {{{ Break english phrases down into their phonemes */
26
26
PHP_FUNCTION (metaphone )
@@ -35,14 +35,13 @@ PHP_FUNCTION(metaphone)
35
35
Z_PARAM_LONG (phones )
36
36
ZEND_PARSE_PARAMETERS_END ();
37
37
38
- if (metaphone ((unsigned char * )ZSTR_VAL (str ), ZSTR_LEN (str ), phones , & result , 1 ) == 0 ) {
39
- RETVAL_STR (result );
40
- } else {
41
- if (result ) {
42
- zend_string_free (result );
43
- }
44
- RETURN_FALSE ;
38
+ if (phones < 0 ) {
39
+ zend_argument_value_error (2 , "must be greater than or equal to 0" );
40
+ RETURN_THROWS ();
45
41
}
42
+
43
+ metaphone ((unsigned char * )ZSTR_VAL (str ), ZSTR_LEN (str ), phones , & result , 1 );
44
+ RETVAL_STR (result );
46
45
}
47
46
/* }}} */
48
47
@@ -145,7 +144,7 @@ static char Lookahead(char *word, int how_far)
145
144
ZSTR_LEN(*phoned_word) = p_idx; \
146
145
}
147
146
/* Slap a null character on the end of the phoned word */
148
- #define End_Phoned_Word { \
147
+ #define End_Phoned_Word () { \
149
148
if (p_idx == max_buffer_len) { \
150
149
*phoned_word = zend_string_extend(*phoned_word, 1 * sizeof(char) + max_buffer_len, 0); \
151
150
max_buffer_len += 1; \
@@ -160,24 +159,13 @@ static char Lookahead(char *word, int how_far)
160
159
#define Isbreak (c ) (!isalpha(c))
161
160
162
161
/* {{{ metaphone */
163
- static int metaphone (unsigned char * word , size_t word_len , zend_long max_phonemes , zend_string * * phoned_word , int traditional )
162
+ static void metaphone (unsigned char * word , size_t word_len , zend_long max_phonemes , zend_string * * phoned_word , int traditional )
164
163
{
165
164
int w_idx = 0 ; /* point in the phonization we're at. */
166
165
size_t p_idx = 0 ; /* end of the phoned phrase */
167
166
size_t max_buffer_len = 0 ; /* maximum length of the destination buffer */
168
-
169
- /*-- Parameter checks --*/
170
- /* Negative phoneme length is meaningless */
171
-
172
- if (max_phonemes < 0 )
173
- return -1 ;
174
-
175
- /* Empty/null string is meaningless */
176
- /* Overly paranoid */
177
- /* assert(word != NULL && word[0] != '\0'); */
178
-
179
- if (word == NULL )
180
- return -1 ;
167
+ ZEND_ASSERT (word != NULL );
168
+ ZEND_ASSERT (max_phonemes >= 0 );
181
169
182
170
/*-- Allocate memory for our phoned_phrase --*/
183
171
if (max_phonemes == 0 ) { /* Assume largest possible */
@@ -194,8 +182,8 @@ static int metaphone(unsigned char *word, size_t word_len, zend_long max_phoneme
194
182
for (; !isalpha (Curr_Letter ); w_idx ++ ) {
195
183
/* On the off chance we were given nothing but crap... */
196
184
if (Curr_Letter == '\0' ) {
197
- End_Phoned_Word
198
- return SUCCESS ; /* For testing */
185
+ End_Phoned_Word ();
186
+ return ;
199
187
}
200
188
}
201
189
@@ -460,8 +448,6 @@ static int metaphone(unsigned char *word, size_t word_len, zend_long max_phoneme
460
448
w_idx += skip_letter ;
461
449
} /* END FOR */
462
450
463
- End_Phoned_Word ;
464
-
465
- return 0 ;
451
+ End_Phoned_Word ();
466
452
} /* END metaphone */
467
453
/* }}} */
0 commit comments