#include "php.h"
#include "php_string.h"
-#define LEVENSHTEIN_MAX_LENGTH 255
-
/* {{{ reference_levdist
* reference implementation, only optimized for memory usage, not speed */
static zend_long reference_levdist(const zend_string *string1, const zend_string *string2, zend_long cost_ins, zend_long cost_rep, zend_long cost_del )
zend_long cost_ins = 1;
zend_long cost_rep = 1;
zend_long cost_del = 1;
- zend_long distance = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|lll", &string1, &string2, &cost_ins, &cost_rep, &cost_del) == FAILURE) {
RETURN_THROWS();
}
- if (ZSTR_LEN(string1) > LEVENSHTEIN_MAX_LENGTH) {
- zend_argument_value_error(1, "must be less than %d characters", LEVENSHTEIN_MAX_LENGTH + 1);
- RETURN_THROWS();
- }
-
- if (ZSTR_LEN(string2) > LEVENSHTEIN_MAX_LENGTH) {
- zend_argument_value_error(2, "must be less than %d characters", LEVENSHTEIN_MAX_LENGTH + 1);
- RETURN_THROWS();
- }
-
- distance = reference_levdist(string1, string2, cost_ins, cost_rep, cost_del);
- RETURN_LONG(distance);
+ RETURN_LONG(reference_levdist(string1, string2, cost_ins, cost_rep, cost_del));
}
/* }}} */
--TEST--
-levenshtein() error conditions
+levenshtein() former error conditions
--FILE--
<?php
+// levenshtein no longer has a maximum string length limit.
+
echo '--- String 1 ---' . \PHP_EOL;
var_dump(levenshtein('AbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsu', 'A'));
try {
--EXPECT--
--- String 1 ---
int(254)
-levenshtein(): Argument #1 ($string1) must be less than 256 characters
+int(255)
--- String 2 ---
int(254)
-levenshtein(): Argument #2 ($string2) must be less than 256 characters
+int(255)