Skip to content

Commit e375ffd

Browse files
author
Ilia Alshanetsky
committed
Added enchant_dict_quick_check() function.
Made enchant_dict_check() return a boolean.
1 parent b303ba0 commit e375ffd

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

ext/enchant/CREDITS

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
enchant
2+
Pierre-Alain Joye, Ilia Alshanetsky

ext/enchant/enchant.c

+43-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
| [email protected] so we can mail you a copy immediately. |
1414
+----------------------------------------------------------------------+
1515
| Author: Pierre-Alain Joye <[email protected]> |
16+
| Ilia Alshanetsky <[email protected]> |
1617
+----------------------------------------------------------------------+
1718
1819
$Id$
@@ -81,6 +82,7 @@ function_entry enchant_functions[] = {
8182
PHP_FE(enchant_dict_store_replacement, NULL)
8283
PHP_FE(enchant_dict_get_error, NULL)
8384
PHP_FE(enchant_dict_describe, NULL)
85+
PHP_FE(enchant_dict_quick_check, third_arg_force_ref)
8486

8587
{NULL, NULL, NULL} /* Must be the last line in enchant_functions[] */
8688
};
@@ -496,8 +498,47 @@ PHP_FUNCTION(enchant_broker_describe)
496498
}
497499
/* }}} */
498500

501+
PHP_FUNCTION(enchant_dict_quick_check)
502+
{
503+
zval *dict, *sugg = NULL;
504+
char *word;
505+
int wordlen;
506+
enchant_dict *pdict;
507+
508+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|z/", &dict, &word, &wordlen, &sugg) == FAILURE) {
509+
RETURN_FALSE;
510+
}
511+
512+
if (sugg) {
513+
zval_dtor(sugg);
514+
}
515+
516+
PHP_ENCHANT_GET_DICT;
517+
518+
if (enchant_dict_check(pdict->pdict, word, wordlen) > 0) {
519+
if (!sugg && ZEND_NUM_ARGS() == 2) {
520+
RETURN_FALSE;
521+
}
522+
523+
int n_sugg;
524+
char **suggs;
525+
526+
array_init(sugg);
527+
528+
suggs = enchant_dict_suggest(pdict->pdict, word, wordlen, &n_sugg);
529+
if (suggs && n_sugg) {
530+
int i;
531+
for (i = 0; i < n_sugg; i++) {
532+
add_next_index_string(sugg, suggs[i], 1);
533+
}
534+
}
535+
RETURN_FALSE;
536+
}
537+
RETURN_TRUE;
538+
}
539+
499540
/* {{{ proto long enchant_dict_check(resource broker)
500-
0 if the word is correctly spelled, positive if not, negative if error */
541+
If the word is correctly spelled return true, otherwise return false */
501542
PHP_FUNCTION(enchant_dict_check)
502543
{
503544
zval *dict;
@@ -511,7 +552,7 @@ PHP_FUNCTION(enchant_dict_check)
511552

512553
PHP_ENCHANT_GET_DICT;
513554

514-
RETURN_LONG((long)enchant_dict_check(pdict->pdict, word, wordlen));
555+
RETURN_BOOL(!enchant_dict_check(pdict->pdict, word, wordlen));
515556
}
516557
/* }}} */
517558

ext/enchant/package.xml

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
<email>[email protected]</email>
1111
<role>lead</role>
1212
</maintainer>
13+
<maintainer>
14+
<user>iliaa</user>
15+
<name>Ilia Alshanetsky</name>
16+
<email>[email protected]</email>
17+
<role>developer</role>
18+
</maintainer>
1319
</maintainers>
1420
<description>Enchant is a binder for libenchant. Libenchant provides a common
1521
API for many spell libraries:
@@ -31,6 +37,7 @@ see www.abisource.com/enchant/</description>
3137
<file role="src" name="config.w32"/>
3238
<file role="src" name="enchant.c"/>
3339
<file role="src" name="php_enchant.h"/>
40+
<file role="doc" name="CREDITS"/>
3441
<dir name="docs" role="doc">
3542
<dir name="examples">
3643
<file name="example1.php"/>

ext/enchant/php_enchant.h

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ PHP_FUNCTION(enchant_dict_is_in_session);
5959
PHP_FUNCTION(enchant_dict_store_replacement);
6060
PHP_FUNCTION(enchant_dict_get_error);
6161
PHP_FUNCTION(enchant_dict_describe);
62+
PHP_FUNCTION(enchant_dict_quick_check);
6263

6364
#ifdef ZTS
6465
#define ENCHANT_G(v) TSRMG(enchant_globals_id, zend_enchant_globals *, v)

0 commit comments

Comments
 (0)