From: Ilia Alshanetsky Date: Tue, 9 Mar 2004 00:31:17 +0000 (+0000) Subject: Added enchant_dict_quick_check() function. X-Git-Tag: RELEASE_0_2_0~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e375ffddb457cd25695c46a720b20f5a8f70ccd7;p=php Added enchant_dict_quick_check() function. Made enchant_dict_check() return a boolean. --- diff --git a/ext/enchant/CREDITS b/ext/enchant/CREDITS new file mode 100644 index 0000000000..481febbfc2 --- /dev/null +++ b/ext/enchant/CREDITS @@ -0,0 +1,2 @@ +enchant +Pierre-Alain Joye, Ilia Alshanetsky diff --git a/ext/enchant/enchant.c b/ext/enchant/enchant.c index 02876c3618..1700279345 100755 --- a/ext/enchant/enchant.c +++ b/ext/enchant/enchant.c @@ -13,6 +13,7 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Pierre-Alain Joye | + | Ilia Alshanetsky | +----------------------------------------------------------------------+ $Id$ @@ -81,6 +82,7 @@ function_entry enchant_functions[] = { PHP_FE(enchant_dict_store_replacement, NULL) PHP_FE(enchant_dict_get_error, NULL) PHP_FE(enchant_dict_describe, NULL) + PHP_FE(enchant_dict_quick_check, third_arg_force_ref) {NULL, NULL, NULL} /* Must be the last line in enchant_functions[] */ }; @@ -496,8 +498,47 @@ PHP_FUNCTION(enchant_broker_describe) } /* }}} */ +PHP_FUNCTION(enchant_dict_quick_check) +{ + zval *dict, *sugg = NULL; + char *word; + int wordlen; + enchant_dict *pdict; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|z/", &dict, &word, &wordlen, &sugg) == FAILURE) { + RETURN_FALSE; + } + + if (sugg) { + zval_dtor(sugg); + } + + PHP_ENCHANT_GET_DICT; + + if (enchant_dict_check(pdict->pdict, word, wordlen) > 0) { + if (!sugg && ZEND_NUM_ARGS() == 2) { + RETURN_FALSE; + } + + int n_sugg; + char **suggs; + + array_init(sugg); + + suggs = enchant_dict_suggest(pdict->pdict, word, wordlen, &n_sugg); + if (suggs && n_sugg) { + int i; + for (i = 0; i < n_sugg; i++) { + add_next_index_string(sugg, suggs[i], 1); + } + } + RETURN_FALSE; + } + RETURN_TRUE; +} + /* {{{ proto long enchant_dict_check(resource broker) - 0 if the word is correctly spelled, positive if not, negative if error */ + If the word is correctly spelled return true, otherwise return false */ PHP_FUNCTION(enchant_dict_check) { zval *dict; @@ -511,7 +552,7 @@ PHP_FUNCTION(enchant_dict_check) PHP_ENCHANT_GET_DICT; - RETURN_LONG((long)enchant_dict_check(pdict->pdict, word, wordlen)); + RETURN_BOOL(!enchant_dict_check(pdict->pdict, word, wordlen)); } /* }}} */ diff --git a/ext/enchant/package.xml b/ext/enchant/package.xml index f075f3f9ac..a8170bbeaa 100755 --- a/ext/enchant/package.xml +++ b/ext/enchant/package.xml @@ -10,6 +10,12 @@ paj@pearfr.org lead + + iliaa + Ilia Alshanetsky + ilia@php.net + developer + Enchant is a binder for libenchant. Libenchant provides a common API for many spell libraries: @@ -31,6 +37,7 @@ see www.abisource.com/enchant/ + diff --git a/ext/enchant/php_enchant.h b/ext/enchant/php_enchant.h index 54ae7910d3..e0d98730ca 100644 --- a/ext/enchant/php_enchant.h +++ b/ext/enchant/php_enchant.h @@ -59,6 +59,7 @@ PHP_FUNCTION(enchant_dict_is_in_session); PHP_FUNCTION(enchant_dict_store_replacement); PHP_FUNCTION(enchant_dict_get_error); PHP_FUNCTION(enchant_dict_describe); +PHP_FUNCTION(enchant_dict_quick_check); #ifdef ZTS #define ENCHANT_G(v) TSRMG(enchant_globals_id, zend_enchant_globals *, v)